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);
        }
    
    }

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

  • 相关阅读:
    外键的缺陷
    laravel 关联模型
    n的阶乘末尾出现的次数
    JavaScript的self和this使用小结
    cocos2dx中的内存管理方式
    c++ 与 lua 简单交互参数介绍
    c++的单例模式及c++11对单例模式的优化
    cocos2dx帧动画
    cocos2dx中坐标系
    cocos2dx中替代goto的用法:do{}while(0)和CC_BREAK_IF
  • 原文地址:https://www.cnblogs.com/Nora-F/p/10345810.html
Copyright © 2011-2022 走看看