How to handle name from children. I'm using gson
.
here is my code and i get illegalstateexception : expected Begin object but was begin array at line ..
i don't know how to iterate gson object
Reader reader = jSONParser.getGSONFromUrl(url);
Root response=null;
try {
response = new Gson().fromJson(reader, Root.class);
person
= new ArrayList<Person>(Arrays.asList(response.person.clone()));
children
= new ArrayList<Child>(Arrays.asList(response.Children.clone()));
job
= response.job;
} catch (Exception e) {
// TODO: handle exception
System.out.println("JSONReader "+e.getMessage());
}
}
public class Root{
@SerializedName("person")
Person[] persons;
@SerializedName("job")
Job job;
@SerializedName("children")
Child[] children;
}
class Child{
int cID;
List<String>names;
}
{
person:[{}, {}, {}..],
job:{..},
children:{"cID":"1", "name":{"firstname":"mark"}}
}
or
{
person:[{}, {}, {}..],
job:{..},
children:{"cID":"1", "name":[{"firstname":"mark"}, {"firstname":"jan"}, {"firstname":"tamara"}...]}
}
How to handle name from children. I'm using gson
.
here is my code and i get illegalstateexception : expected Begin object but was begin array at line ..
i don't know how to iterate gson object