Parsing json (2 arrays) in Android

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!

Answers


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"


Need Your Help

Cannot get rid of a bizarre 2px space between my child image and parent div

jquery html css

I have tried everything I know. I'm beginning to think it's being created by Tumblrs javascript.

MEF giving CompositionException

mef

I am new to MEF and I am trying this following program.