Rafa
Rafa

Reputation: 3349

JSONException end of input at character 0 error

I'm using OKHttp and getting a JSONException end of input at character 0 of error and I tried printing out the response value. It successfully prints out the first time I log it, but after I assign it to a string value and try to print that out, it prints out

`D/MAIN ACTIVITYjsonObject﹕ [ 12-09 22:31:52.780 25187:25215 I/FilterUnInstaller ] FilterUninstaller.java : removeFromDB()`

Here is the code I'm using

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

        }
});

Upvotes: 0

Views: 634

Answers (1)

BNK
BNK

Reputation: 24114

Don't call response.body().string() twice. Instead, use String jsonData= response.body().string(); then Log.d(ACTIVITY, jsonData); and Log.d(ACTIVITY + "jsonObject", jsonData);

Upvotes: 2

Related Questions