-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?

5

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

1 Comment

Still i feel it is the responsibility of the asker to decide ,he will know where this may lead him in the future.

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.