Using http://central.maven.org/maven2/org/json/json/20180813/json-20180813.jar Jar,
public static void main(String[] args) {
String input="[{\"nom\":\"Nexus09\",\"poste\":\"4319\"},{\"nom\":\"Nexus08\",\"poste\":\"4312\"},{\"nom\":\"Nexus07\",\"poste\":\"4306\"}]";
JSONArray jsonArray = new JSONArray(input);
jsonArray.forEach(j->System.out.println(j.toString()));
}
To parse the nested JSONObject
, It can be done like below,
public static void main(String[] args) {
String input="[{\"nom\":\"Nexus09\",\"poste\":\"4319\"},{\"nom\":\"Nexus08\",\"poste\":\"4312\"},{\"nom\":\"Nexus07\",\"poste\":\"4306\"}]";
JSONArray jsonArray = new JSONArray(input);
for(Object object:jsonArray) {
if(object instanceof JSONObject) {
JSONObject jsonObject = (JSONObject)object;
Set<String> keys =jsonObject.keySet();
for(String key:keys) {
System.out.println(key +" :: "+jsonObject.get(key));;
}
}
}
}