1

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!

1
  • Sotirios Delimanolis, Instead 1 indicates nothing. Commented Mar 1, 2014 at 19:08

1 Answer 1

2

your jsonObject is within the jsonArray

Do like this

JSONArray jarray= new JSONArray(EntityUtils.toString(responseEntity));
String error=jarray.getJSONObject(0).getString("error");
Sign up to request clarification or add additional context in comments.

2 Comments

Nambi Narayanan, Thank you!
@Aydomir It's Ok Glad i would help :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.