一.日志打印:
error:Value okhttp3.internal.http.RealResponseBody@49ebb98 of type java.lang.String cannot be converted to JSONArray
二.原文代码:
1.错误:String str = response.body().toString();
2.正确:String str = response.body().string();
三.原因:
1.toString()可以将所有的的数据都转换为字符串,但是要排除null 和 undefined
.网页代码String()可以将null和undefined转换为字符串,但是没法转进制字符串
2.在stackoverflow上查到的解释是:
toString(): This returns your object in string format.(以字符串的格式返回你的对象)
string(): This returns your response。(返回你的response)
本文解析了使用OkHttp时常见的响应处理错误,详细对比了response.body().toString()与response.body().string()的区别,强调了后者在获取响应内容时的正确用法。
4269

被折叠的 条评论
为什么被折叠?



