我正在使用OKHttp并收到JSONException end of input at character 0 of
错误,我尝试打印出响应值。它在我第一次登录时成功打印出来,但是在我将其分配给字符串值并尝试打印出来之后,它会打印出来
`D/MAIN ACTIVITYjsonObject﹕ [ 12-09 22:31:52.780 25187:25215 I/FilterUnInstaller ] FilterUninstaller.java : removeFromDB()`
这是我正在使用的代码
@Override
public void onResponse(Response response) throws IOException {
//this prints out an actual json formatted response
Log.d(ACTIVITY, response.body().string());
try{
if(response.isSuccessful()) {
String jsonData = response.body().string();
//this gives me the previously stated response
Log.d(ACTIVITY + "jsonObject", jsonData);
mWeather = getWeatherData(jsonData);
Log.d(ACTIVITY + "Temperature", mWeather.getTemp());
}
} catch(JSONException e){
Log.d(ACTIVITY + " JSONEXCEPTION", e.getMessage());
} catch(IOException e){
Log.d(ACTIVITY + " IOEXCEPTION", e.getMessage());
}
}
});
答案 0 :(得分:2)
请勿两次致电response.body().string()
。相反,请使用String jsonData= response.body().string();
,然后Log.d(ACTIVITY, jsonData);
和Log.d(ACTIVITY + "jsonObject", jsonData);