Answer the question
In order to leave comments, you need to log in
How to loop through an array of objects in java?
Hello.
I apologize in advance if I'm asking a too primitive question, but Google does not return results or I cannot formulate the question correctly.
How can one iterate over an array of objects in Java?
those. the structure is as follows:
[
{
"name":"Alex",
"age":"40"
},
{
"name":"John",
"age":"40"
}
]
for (Object child : m.getChilds()) {
for (String field : child){
System.out.println(field.name);
}
}
Answer the question
In order to leave comments, you need to log in
There are a lot of examples. Please: https://duckduckgo.com/?q=load+and+traverse+json+i...
The trick is that the compiler will not see your fields in the object class. Create a class with the desired structure and just cast an object to it.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question