在使用okhttp请求网络数据的时候碰到了json汉字乱码问题。
1.可能是服务器和客户端的编码不一致导致的
经过和服务端沟通(也可以查看响应头信息),发现服务端和客户端使用的都是utf-8,排除。
2.okhttp本身的问题
经查阅资料,如果自己设置了
addHeader(“Accept-Encoding”, “gzip”),
会导致json乱码,注掉该行代码即可解决问题。
原因:
When you provide your own Accept-Encoding header you’re instructing OkHttp that you want to do your own decompression. By omitting it, OkHttp will take care of both adding the header and the decompression.
当你添加自己的 Accept-Encoding 头信息时, OkHttp会认为你要自己处理解压缩步骤. 删除这个头信息后, OkHttp 会自动处理加头信息和解压缩的步骤.
---------------------
作者:chinajpr
来源:CSDN
原文:https://blog.csdn.net/chinajpr/article/details/54892751
版权声明:本文为博主原创文章,转载请附上博文链接!










