• volley实现传入string 返回JsonArrayObject


    接着 上一篇 https://www.cnblogs.com/Nora-F/p/10320335.html

    public class CustomArrayRequest extends Request<JSONArray> {
    
        private Listener<JSONArray> listener;
        private Map<String, String> params;
    
        public CustomArrayRequest(String url, Map<String, String> params,
                             Listener<JSONArray> reponseListener, ErrorListener errorListener) {
            super(Method.GET, url, errorListener);
            this.listener = reponseListener;
            this.params = params;
        }
    
        public CustomArrayRequest(int method, String url, Map<String, String> params,
                             Listener<JSONArray> reponseListener, ErrorListener errorListener) {
            super(method, url, errorListener);
            this.listener = reponseListener;
            this.params = params;
        }
    
        protected Map<String, String> getParams()
                throws com.android.volley.AuthFailureError {
            return params;
        };
    
        @Override
        protected Response<JSONArray> parseNetworkResponse(NetworkResponse response) {
            try {
                String jsonString = new String(response.data,
                        HttpHeaderParser.parseCharset(response.headers));
                return Response.success(new JSONArray(jsonString),
                        HttpHeaderParser.parseCacheHeaders(response));
            } catch (UnsupportedEncodingException e) {
                return Response.error(new ParseError(e));
            } catch (JSONException je) {
                return Response.error(new ParseError(je));
            }
        }
    
        @Override
        protected void deliverResponse(JSONArray response) {
            // TODO Auto-generated method stub
            listener.onResponse(response);
        }
    
    }

    其实只是改变了一下 浅蓝 位置 的类型

  • 相关阅读:
    java 生成随机字符串
    java 使用抽象工厂封装特性方法
    c3p0 连接池配置数据源
    sql 语法总结
    HttpRequestUtils post get请求
    Spring事务(1)
    Spring增强
    面试题
    Java的三种代理模式
    Spring中bean的作用域与生命周期
  • 原文地址:https://www.cnblogs.com/Nora-F/p/10345810.html
Copyright © 2020-2023  润新知