user1918034
user1918034

Reputation: 191

End of input at character 0 while parsing json response from server

I am sending the the data to server, and trying to parse the json response which is of the form {"count":"2"}, but I am getting above exception

This is my code

post(serverUrl, params);

HttpClient httpClient = new DefaultHttpClient();
try{
    get = new HttpPost(url);
    r = httpClient.execute(get);
    he = r.getEntity();
    InputStream is = he.getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"), 8);
    StringBuilder sb = new StringBuilder();

    String line = null;
    while ((line = reader.readLine()) != null) { sb.append(line + "\n"); }

    String result = sb.toString();
    jObj = new JSONObject(result);
    Log.d(TAG, "Count is" + jObj);
    count = jObj.getString("count");
    Log.d(TAG, "Count is" + count);
}
catch (Exception e) { e.printStackTrace(); }

Upvotes: 0

Views: 1416

Answers (2)

user1918034
user1918034

Reputation: 191

This is my server code, and I am keeping the default value, so it definately can't be empty

$jsonOutput = array('count' => $i);
header('Content-type: application/json');
echo json_encode($jsonOutput);

Upvotes: 0

nisha.113a5
nisha.113a5

Reputation: 2024

There is possibility for blank value in response. It cannot consider as null.. This error because of blank response.

Upvotes: 2

Related Questions