Hello I am stuck in converting JSON NESTED Array to JAVA Objects using GSON labirary.
Here is my JSON String
[{\"name\":\"3214657890RootSAPSSE\",\"children\":[{\"name\":\"672BENIAMEEN .Sales Base Market SectionCustomer Representative\"},{\"name\":\"672BENIAMEEN .Sales Base Market SectionPeão\"}]}]
I tested my code with x="[{\"name\":\"MyNode\"}]";
and for this my java code is
Gson gson = new Gson();
java.lang.reflect.Type type = new TypeToken<List<EmployeeJSONObj>>(){}.getType();
List<EmployeeJSONObj>l = gson.fromJson(x, type);
System.out.println("hello "+l.get(0).getName());
AND EmployeeJSONObj is class
public class EmployeeJSONObj {
private String name;
EmployeeJSONObj()
{
}
public String getName()
{
return name;
}
}
This is working fine. But my this code gives me error when I change the JSON String to
[{\"name\":\"3214657890RootSAPSSE\",\"children\":[{\"name\":\"672BENIAMEEN .Sales Base Market SectionCustomer Representative\"},{\"name\":\"672BENIAMEEN .Sales Base Market SectionPeão\"}]}]
This is a tree. I want generic solution, which can traverse the whole nested json string. I'm stuck in the middle of a project. Please help me to solve this.
Thanks