0

I need to parse a JSON with two arrays.

resp: {"attending": [], "people": []}

I tried this

JSONObject AttendingArray = new JSONObject(resp);               
JSONArray ParkArray = new JSONArray("people");
JSONArray AttendingArray = new JSONArray("attending");

But it doesn't work

12-01 22:47:53.074: WARN/System.err(30814): org.json.JSONException: Value people of type java.lang.String cannot be converted to JSONArray

Thanks!

1
  • Which json api are you using? Which line causes the exception? Commented Dec 1, 2011 at 22:06

1 Answer 1

1
JSONObject obj = new JSONObject(resp);               
JSONArray ParkArray = new JSONArray(obj.getString("people"));
JSONArray AttendingArray = new JSONArray(obj.getString("attending"));

You must pass actual JSON to the JSONArray constructor, not just the name of the json array - the new JSONArray constructor call doesn't know about the response, so you need to give it some data, not just "people"

Sign up to request clarification or add additional context in comments.

1 Comment

Ah sorry, was just doing it from memory woops

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.