Android使用volly请求utf-8报错Value  of type java.lang.String cannot be converted to

来源:互联网 发布:天刀官网丐妹捏脸数据 编辑:程序博客网 时间:2024/03/29 09:23

服务器json是utf-8格式的

Android下用volly请求总是报错

Value ï»¿ of type java.lang.String cannot be converted to


解决方法:

复写volly的

JsonObjectRequest 
public class JsonObjectUTF8Request extends JsonObjectRequest {    public JsonObjectUTF8Request(String url, JSONObject jsonRequest, Response.Listener<JSONObject> listener,                                 Response.ErrorListener errorListener) {        super(url, jsonRequest, listener, errorListener);    }    @Override    protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {        try {            String jsonString =                    new String(response.data, "utf-8");            MyUtils.ShowLog("请求打印"+jsonString);            return Response.success(new JSONObject(jsonString),                    HttpHeaderParser.parseCacheHeaders(response));        } catch (UnsupportedEncodingException e) {            return Response.error(new ParseError(e));        } catch (JSONException je) {            return Response.error(new ParseError(je));        }    }}

阅读全文
0 0
原创粉丝点击