I have this in my json file(see below) and I want to read it to console.
{
"employeeData": {
"employmentStartDate": "1997-12-3",
"employmentEndDate": "1997-12-03",
"suspensionPeriodList": [
{"startDate": "1997-05-01", "endDate": "1997-07-31" },
{"startDate": "1997-08-02", "endDate": "1997-09-31" }
]
}
}
I tried in some ways but my problem is the 'employeeData'. If it wasn't there
I could easily get the employmentStartDate by JSONArray JSON = (JSONArray) JSONObj.get("employmentStartDate");
JSONParser parser = new JSONParser();
try {
Object obj = parser.parse(new FileReader("src\\main\\resources\\input.json"));
JSONObject JSONObj = (JSONObject) obj;
JSONArray JSON = (JSONArray) JSONObj.get("employeeData");
Iterator<String> iterator = JSON.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
} catch (Exception e) {
e.printStackTrace();
}
}
I tried to put the EmployeeData into an array but this doesn't work of course.