java - How to deserialize object or array -
how handle name children. i'm using gson. here code , illegalstateexception : expected begin object begin array @ line .. don't know how iterate gson object
reader reader = jsonparser.getgsonfromurl(url); root response=null; seek { 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; } grab (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 handle name children. i'm using gson. here code , illegalstateexception : expected begin object begin array @ line .. don't know how iterate gson object
to name need have next path:
children.name
if have array of firstnames, should access array:
children.name.firstname[number]
since "name" object type, can refer of it's fields via "."
java gson
No comments:
Post a Comment