JSONException end of input at character 0 错误

JSONException end of input at character 0 error

我正在使用 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());
            }

        }
});

不要调用 response.body().string() 两次。相反,使用 String jsonData= response.body().string(); 然后 Log.d(ACTIVITY, jsonData);Log.d(ACTIVITY + "jsonObject", jsonData);