关于volley从后台获取json文件解析乱码问题解决

2018-11-29  本文已影响0人  禄子_c79b
 url = updateUrl;//升级文件路径

// StringRequest request = new StringRequest(url, new Response.Listener<String>() {
MyStringRequest request = new MyStringRequest(url, new Response.Listener<String>() {

        @Override
        public void onResponse(String arg0) {
            updatejson(arg0.toString());

        }

    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError arg0) {
            // TODO Auto-generated method stub

        }
    });

    new Volley().newRequestQueue(this).add(request);

2 乱码问题解决方案
解决这个问题有两个方法:

public class MyStringRequest extends StringRequest {
@Override
protected Response<String> parseNetworkResponse(NetworkResponse response) {
String parsed;
try {
parsed = new String(response.data, "utf-8"));
} catch (UnsupportedEncodingException e) {
parsed = new String(response.data);
}
return Response.success(parsed, HttpHeaderParser.parseCacheHeaders(response));
}

}

作者:chengshuyuan_uestc
来源:CSDN
原文:https://blog.csdn.net/chengshuyuan_uestc/article/details/51755191
版权声明:本文为博主原创文章,转载请附上博文链接!

上一篇下一篇

猜你喜欢

热点阅读