android 解决volley中StringRequest返回乱码

继承StringRequest类 重写


/*
* 自定义request类 目的修改volley编码为utf-8 默认为Latin1 中文显示乱码
*/
public static class Utf8StringRequest extends StringRequest {


public Utf8StringRequest(int method, String url,
Listener listener, ErrorListener errorListener) {
super(method, url, listener, errorListener);
// TODO Auto-generated constructor stub
}


@Override
protected Response parseNetworkResponse(NetworkResponse response) {


String parsed = null;
try {
parsed = new String(response.data,
"utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return Response.success(parsed,
HttpHeaderParser.parseCacheHeaders(response));


}
}

你可能感兴趣的:(突然兴致来了,安卓)