android - Java ClassCastException on getting JSON parsed java object -
android - Java ClassCastException on getting JSON parsed java object -
hi guys have problem in java. problem around parsing json jackson instructed. json parsed well, that's not problem. problem lies in have multiple json items in 1 json. i've parsed this:
objectmapper objectmapper = new objectmapper(); seek { list<unit> unitlist = objectmapper.readvalue(json,list.class); system.out.println("unitsize " + string.valueof(unitlist.size())); system.out.println(unitlist.get(0).getunitemail()); } grab (ioexception e) { e.printstacktrace(); }
and @ unitsize it'll tell me have exactly 5 objects of unit type, okay, when want out of list says me this:
exception in thread "main" java.lang.classcastexception: java.util.linkedhashmap cannot cast com.reddatura.api.httprequest$unit
i've googled it, nil relevant. should problem
edit:
here class snippet:
@jsonignoreproperties(ignoreunknown = true) public class unit { @jsonproperty("unitid") int unitid; @jsonproperty("unitname") string unitname; @jsonproperty("unitlogo") string unitlogo; @jsonproperty("unitaddress") string unitaddr; //other fields, getters setters @jsoncreator public unit() { } }
i want parse model
do :
jsonobject jobject = new jsonobject(jsonstring); jsonarray jsonarray = jobject.getjsonarray("posts"); (int = 0; < jsonarray.length(); i++) { int = jsonarray.getjsonobject(i).getint("a"), string s = jsonarray.getjsonobject(i).getstring("b")); }
jsonstring string variable , must json syntax
java android json
Comments
Post a Comment