-1

I am trying to parse JSON data which is like:

 {
      "name1": "xyz",
      "data":[{
          "education": {
            "School": "xyz",
             "ug": "xyz",
             "Activities": [{
              ...
             }],
            "Prizes": [{
            ...
            }],
            "Curriculum":[{
             ...
            }]
         }
      }]      
     }

How can I fetch the JSONArray of activities, prizes, curriculum values?

Waseem Akram
  • 215
  • 2
  • 14

1 Answers1

2

If you just want the values of the first element (you are looking at an array so you may want all the elements) you can try this:

String src = " { ... } "; //your json
JSONObject mainObject= new JSONObject(src);
JSONArray dataArray= mainObject.getJSONArray("data");
JSONObject firstDataObject = dataArray.getJSONObject(0); //get the first element
JSONObject educationObject = firstDataObject.getJSONObject("education");
JSONArray activitiesArray = educationObject.getJSONArray("Activities");
//do something with the array. Ex: activitiesArray.getJSONObject(0);
JSONArray prizesArray = educationObject.getJSONArray("Prizes");
//do something with the array
JSONArray curriculumArray = educationObject.getJSONArray("Curriculum");
//do something with the array
Gianni B.
  • 2,691
  • 18
  • 31