I am using org.json.simple library to construct JSONArray of JSONObject. So my structure looks like
c= [
{
"name":"test",
"age":1
},
{
"name":"test",
"age":1
}
]
To iterate the array in java, I tried
for (int i = 0; i < c.size(); i++) {
JSONObject obj = (JSONObject) c.get(i);
System.out.println(obj.get("name"));
}
It printed null, but when tried to print the obj.toString, it prints the JSON string as expected.
I am using org.json.simple jar, so cannot use the methods defined org.json.JSONArray or org.json.JSONObject.
Any ideas to get the values from the object with their key?
i< c=arr.size()? Which typechas?c = arr.size()and thenc.get(i)? That shouldn't compile. So please post the exact code that demonstrates the issue.