Volley StringRequest 接收出现乱码问题

1、首先要保持服务端返回来的response.setContentType("text/html; charset=utf-8")与客户端接收的字符集编码一致。

2、如果还是出现乱码问题,尝试重写StringRequest或JSONObjectRequest:

@Override
    protected Response<String> parseNetworkResponse(NetworkResponse response) {
        // TODO Auto-generated method stub
        String str = null;
        try {
            str = new String(response.data,"utf-8");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return Response.success(str, HttpHeaderParser.parseCacheHeaders(response));
    }

相关推荐