nested json parsing for android with jackson -



nested json parsing for android with jackson -

i started android prograamming , found nice tutorial using imdb api. instead of using xml in tutorial utilize json , recevied json have problem. person.json:

[ { "score":1, "popularity":3, "name":"brad pitt", "id":287, "biography":"test", "url":"http://www.themoviedb.org/person/287", "profile":[ { "image":{ "type":"profile", "size":"thumb", "height":68, "width":45, "url":"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w45/w8zjqun7tzlm6fy9mfgkihxp3cb.jpg", "id":"4ea5cb8c2c0588394800006f" } }, { "image":{ "type":"profile", "size":"profile", "height":281, "width":185, "url":"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w185/w8zjqun7tzlm6fy9mfgkihxp3cb.jpg", "id":"4ea5cb8c2c0588394800006f" } }, { "image":{ "type":"profile", "size":"h632", "height":632, "width":416, "url":"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/h632/w8zjqun7tzlm6fy9mfgkihxp3cb.jpg", "id":"4ea5cb8c2c0588394800006f" } }, { "image":{ "type":"profile", "size":"original", "height":1969, "width":1295, "url":"http://d3gtl9l2a4fn1j.cloudfront.net/t/p/original/w8zjqun7tzlm6fy9mfgkihxp3cb.jpg", "id":"4ea5cb8c2c0588394800006f" } } ], "version":685, "last_modified_at":"2013-02-16 07:11:15 utc" } ]

my 2 object them:

public class person implements serializable { private static final long serialversionuid = 6794898677027141412l; public string score; public string popularity; public string name; public string id; public string biography; public string url; public string version; public string lastmodifiedat; public profile profile; } public class profile implements serializable { private static final long serialversionuid = -8735669377345509929l; public arraylist<image> imageslist; } public class image implements serializable { private static final long serialversionuid = -2428562977284114465l; public string type; public string url; public string size; public int width; public int height; }

ı couldnt figure out how retrieve person list using jackson object mapper. when utilize one:

objectmapper mapper = new objectmapper(); person person= mapper.readvalue(jsonresponsestring, person.class);

i got:

02-16 18:34:48.010: w/system.err(376): com.fasterxml.jackson.databind.jsonmappingexception: can not deserialize instance of com.example.imdbsearcher.model.person out of start_array token 02-16 18:34:48.180: w/system.err(376): @ [source: java.io.stringreader@40a81778; line: 1, column: 1] 02-16 18:34:48.554: w/system.err(376): @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:599) 02-16 18:34:48.830: w/system.err(376): @ com.fasterxml.jackson.databind.deserializationcontext.mappingexception(deserializationcontext.java:593)

i have changed retrieve method advice of keith , crdnilfan. have problem attribute of profile.

i realized missing 1 in person object , basicly have created new profile object , moved imagelist class.

i have updated pojo's above.

but getting same error profile.

can not deserialize instance of com.example.imdbsearcher.model.profile out of start_array token

you need deserialize list, json array:

list<person> people = mapper.readvalue( jsonresponsestring, new typereference<list<person >>(){});

however, after have additional deserialization errors because of profile property in json. checkout: http://jackson.codehaus.org/1.5.7/javadoc/org/codehaus/jackson/annotate/jsonignoreproperties.html

update:

public class person implements serializable { public list<object> profile; public string score; public string popularity; public string name; public string id; public string biography; public string url; public string version; public string last_modified_at; }

there several ways deal this. give linked hash map profile.

alternatively, if command json format, alter profile syntax this:

"profile":[ image:..., image:... ]

android json jackson

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -