0

I've got an JSON array, and I would like to select the data from it. I would like to get all subjects, but I don't know how to do it.

Code:

JSONObject jsonObject = new JSONObject(thatarray);
JSONArray jsonArray = jsonObject.getJSONArray("response");
int arrSize = jsonArray.length();
List<Integer> sub = new ArrayList<Integer>(arrSize);

for (int i = 0; i < arrSize; ++i) {
    jsonObject = jsonArray.getJSONObject(i);
    System.out.println("Output: " + jsonObject.toString());
}
1
  • 2
    You want to get list of all subject ?? Commented Jun 4, 2016 at 12:05

1 Answer 1

3

Actually "response" is jsonObject and "data" is jsonArray.. u can differentiate between jsonArray and jsonObject by viewing {} and []... hope it will help :)

I tried below code myself on your JSON and it is working.

 try {
        JSONObject jsonObject = new JSONObject(thatarray);
        jsonObject = jsonObject.getJSONObject("response");
        JSONArray jsonArray = jsonObject.getJSONArray("data");

        JSONArray jsonArraysubject;
        for (int i = 0; i < jsonArray.length() - 1; i++) {
            jsonObject = jsonArray.getJSONObject(i);
            jsonArraysubject = jsonObject.getJSONArray("subjects");

            Log.d("MyLog", jsonArraysubject + "");
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
Sign up to request clarification or add additional context in comments.

Comments

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.