2015-12-10 45 views
0

我正在使用OKHttp並且出現JSONException end of input at character 0 of錯誤,我嘗試打印出響應值。它成功地打印出我第一次登陸,但後,我把它分配給一個字符串值,並嘗試打印出來,它打印出JSONException在字符0錯誤處輸入結束

`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()); 
      } 

     } 
}); 

回答

2

請勿撥打response.body().string()兩次。相反,使用String jsonData= response.body().string();,然後Log.d(ACTIVITY, jsonData);Log.d(ACTIVITY + "jsonObject", jsonData);

相關問題