Since, the names of the array are child1
and child2
(which means the names are different), inside the parent object , first you have to fetch these names, and then for each array, fetch date and time.
Here struct
, is the jsonString:
JSONParser parser = new JSONParser();
Object obj = parser.parse(struct);
JSONObject lev1 = (JSONObject) obj;
Object jObj = lev1.get("parent");
List keys = new ArrayList();
if (jObj instanceof Map) {
Map map = (Map) jObj;
Set keySet = map.keySet();
for (Object s : keySet) {
JSONObject jsonObj = (JSONObject) jObj;
JSONArray jarr = (JSONArray) jsonObj.get(s.toString());
for (int i = 0; i < jarr.size(); i++) {
Object get = jarr.get(i);
JSONObject job = (JSONObject) get;
String date = job.get("date").toString();
String time = job.get("time").toString();
System.out.println("Date: " + date + " , Time: " + time);
}
}
}