-1

I have this string which ive validated as JSON:

{"listings":[{"Listing_ID":"1","Event_ID":"1","Venue_ID":"1","Start_Date":"19\/11\/2013","End_Date":"04\/01\/2014","Frequency":"Every Day"},{"Listing_ID":"2","Event_ID":"1","Venue_ID":"4","Start_Date":"20\/01\/2014","End_Date":"21\/01\/2014","Frequency":"Every 2 Da"},{"Listing_ID":"3","Event_ID":"3","Venue_ID":"4","Start_Date":"22\/01\/2014","End_Date":"23\/01\/2014","Frequency":"Every Day"}]}

And i wish to convert it into a JSON array. Ive read around and believe i first have to turn it into an object but im struggling to find a solution.

Any help would be much appreciated.

2
  • there's no such thing as "json array". There's json strings, which contain encoded data structures... What you have there is a json string which contains an object containing an array of objects... if it gets decoded. Commented Feb 20, 2014 at 20:39
  • This might help: stackoverflow.com/questions/5245840/… Commented Feb 20, 2014 at 20:42

1 Answer 1

0

You should be able to use the JSONArray object for this. http://developer.android.com/reference/org/json/JSONArray.html Try using it with the JSONTokener. http://developer.android.com/reference/org/json/JSONTokener.html

Here's an example:

String json = "{\"listings\":[{\"Listing_ID\":\"1\",\"Event_ID\":\"1\",\"Venue_ID\":\"1\",\"Start_Date\":\"19\/11\/2013\",\"End_Date\":\"04\/01\/2014\",\"Frequency\":\"Every Day\"},{\"Listing_ID\":\"2\",\"Event_ID\":\"1\",\"Venue_ID\":\"4\",\"Start_Date\":\"20\/01\/2014\",\"End_Date\":\"21\/01\/2014\",\"Frequency\":\"Every 2 Da\"},{\"Listing_ID\":\"3\",\"Event_ID\":\"3\",\"Venue_ID\":\"4\",\"Start_Date\":\"22\/01\/2014\",\"End_Date\":\"23\/01\/2014\",\"Frequency\":\"Every Day\"}]}";
JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
JSONArray locations = object.getJSONArray("listings");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.