Question

This is my Java code:

...
HttpResponse response = httpclient.execute(httppost);
HttpEntity responseEntity = response.getEntity();
JSONObject serverResponse = new JSONObject(EntityUtils.toString(responseEntity));
String error = serverResponse.getString("error");
text1.setText(error);
...

I can not parse JSON.

JSON:

[{"error":"1"}]

Thank you!

Was it helpful?

Solution

your jsonObject is within the jsonArray

Do like this

JSONArray jarray= new JSONArray(EntityUtils.toString(responseEntity));
String error=jarray.getJSONObject(0).getString("error");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top