-2

i have a jsonArray like this. how can i get each array element form java

[{"subjectname":"Health","classKey":5084485095784448,"staffKeyId":4819823842295808,"subjectKeyId":5756749483081728,"class":"8C"},{"subjectname":"Civics","classKey":5641826627223552,"staffKeyId":4549155540172800,"subjectKeyId":5563198258282496,"class":"8B"}]

1 Answers1

0

Simply use Jackson JSON Parser (https://github.com/FasterXML/jackson)

String jsonString = "[{\"n\":0},{\"n\":1}]"; // add your JSON here
ObjectMapper mapper = new ObjectMapper();
JsonNode actualObj = mapper.readTree(jsonString);
Iterator<JsonNode> it = actualObj.iterator();
while(it.hasNext()) {
  JsonNode next = it.next();
  System.out.println(next.get("n"));
}
kolmio23
  • 11
  • 1
  • 4