一.日誌打印:
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)