JSONException在字符0错误处输入结束

时间:2015-12-10 04:54:34

标签: android json okhttp

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

        }
});

1 个答案:

答案 0 :(得分:2)

请勿两次致电response.body().string()。相反,请使用String jsonData= response.body().string();,然后Log.d(ACTIVITY, jsonData);Log.d(ACTIVITY + "jsonObject", jsonData);