Android—Volley:接收服务端发送的json数据乱码问题解决

new JsonObjectRequest中重写方法parseNetworkResponse,内容如下:

    /**
             * 重写此方法不会导致乱码
             */
            @Override
            protected Response<JSONObject> parseNetworkResponse(
                    NetworkResponse response) {
                response.headers.put("HTTP.CONTENT_TYPE", "utf-8");
                try {
                    String jsonString = new String(response.data, "utf-8");
                    return Response.success(new JSONObject(jsonString),
                            HttpHeaderParser.parseCacheHeaders(response));
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    return Response.error(new ParseError(e));
                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    return Response.error(new ParseError(e));
                }

            }

 

posted @ 2016-11-09 18:12  奋斗者—cyf  阅读(879)  评论(0编辑  收藏  举报