zoukankan      html  css  js  c++  java
  • 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);
        }
    
    }

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

  • 相关阅读:
    circle
    pq
    graph
    matrix
    计数(count)
    想象一下(imagine)
    出租车(taxi)
    字符串函数 (strfun)
    Sabota?
    3973: seq
  • 原文地址:https://www.cnblogs.com/Nora-F/p/10345810.html
Copyright © 2011-2022 走看看