-2

I am developing a android application which fetches some data from the server. I use JSON for that. I have to parse a JSON response which has a structure like below:

{
  "dataset1":["1", "2", "3", "4"],
  "dataset2":["1", "2", "3", "4"],
  "dataset3":["1", "2", "3", "4"],
  "dataset4":["1", "2", "3", "4"]
}

I tried searching the internet but couldn't get an idea how to parse a response like this. Can anyone please show me a way to do this?

jbr
  • 6,198
  • 3
  • 30
  • 42
Lestart Seth
  • 49
  • 2
  • 5
  • https://github.com/google-gson/google-gson – DSF Apr 08 '15 at 12:59
  • 2
    [try this](http://26.media.tumblr.com/tumblr_layxkurNJE1qzpwi0o1_500.jpg) – M D Apr 08 '15 at 13:00
  • "tried searching the internet". have you tried searching on stackoverflow.com? There are tons of JSON related questions here. Including a lot of duplicates that also answer your question – Ivo Apr 08 '15 at 13:01
  • try this http://stackoverflow.com/questions/5650171/parsing-json-array-within-json-object – Raghavendra Apr 08 '15 at 13:02
  • try this http://stackoverflow.com/questions/17136769/how-to-parse-jsonarray-in-android – sham Apr 08 '15 at 13:12

1 Answers1

10

You can use this

JSONObject jsonObject = new JSONObject(jsonString);
JSONArray jsonDataset1 = jsonObject.getJSONArray("dataset1");
JSONArray jsonDataset2 = jsonObject.getJSONArray("dataset2");
JSONArray jsonDataset3 = jsonObject.getJSONArray("dataset3");
JSONArray jsonDataset4 = jsonObject.getJSONArray("dataset4");
StackOverflower
  • 5,463
  • 13
  • 58
  • 89