I have a JsonArray
and I am using the implementation as given in Java EE 7. How do I iterate thorugh this JsonArray
?
I have searched thorugh this site but have found only answer which relate to org.json.JSONArray
(like this Accessing members of items in a JSONArray with Java) which I cannot use as javax.json.JsonArray
does not have the length method.
Looking to javadoc will show that it extends List
, so you can iterate with for loop:
javax.json.JsonArray value = javax.json.Json.createArrayBuilder()
.add(javax.json.Json.createObjectBuilder()
.add("type", "home")
.add("number", "212 555-1234"))
.add(javax.json.Json.createObjectBuilder()
.add("type", "fax")
.add("number", "646 555-4567"))
.build();
for (javax.json.JsonValue jsonValue : value) {
System.out.println(jsonValue);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With