java - JSONObject["user_birthday"] not a string -
sorry repeated problem didn't found answer on google. trying parse json object of setter/getter class.
public arraylist<user> getarraylist(stringbuffer jsonreceived){ arraylist<user> userarraylist = new arraylist<user>(); jsonobject json = new jsonobject(jsonreceived.tostring()); jsonarray usertable = json.getjsonarray("user"); (int = 0; < usertable.length(); i++) { user user = new user(); user.setid(usertable.getjsonobject(i).getint("user_id")); user.setlastname(usertable.getjsonobject(i).getstring("user_last_name")); user.setfirstname(usertable.getjsonobject(i).getstring("user_first_name")); user.setemail(usertable.getjsonobject(i).getstring("user_email")); system.out.println(usertable.getjsonobject(i).getstring("user_birthday")); string datestr = usertable.getjsonobject(i).getstring("user_birthday"); simpledateformat sdf = new simpledateformat("yyyy-mm-dd"); try { date birthdate = sdf.parse(datestr); user.setbirthday(birthdate); } catch (parseexception e) { e.printstacktrace(); } user.setcountry(usertable.getjsonobject(i).getstring("user_country")); user.setcity(usertable.getjsonobject(i).getstring("user_city")); userarraylist.add(user); } system.out.println("la list d'utilisateurs : "+usertable.tostring()); system.out.println("arraylist : "+userarraylist.tostring()); return userarraylist; }
here mon json string user :
{ "tag": "getusers", "success": 1, "error": 0, "user": [ { "user_id": "1", "user_last_name": "alain", "user_first_name": "ron", "user_birthday": "2014-02-01", "user_email": "alain@ron.fr", "user_country": "", "user_city": "" }, { "user_id": "2", "user_last_name": "rodrigues", "user_first_name": "richard", "user_birthday": null, "user_email": "richard@r.fr", "user_country": null, "user_city": null } ]}
and error log :
exception in thread "awt-eventqueue-0" org.json.jsonexception: jsonobject["user_birthday"] not string. @ org.json.jsonobject.getstring(jsonobject.java:661) @ fr.moveo.applicationlourde.services.abstractmethods.getarraylist(abstractmethods.java:50) @ fr.moveo.applicationlourde.views.frames.windowconnexion.actionperformed(windowconnexion.java:75) @ javax.swing.abstractbutton.fireactionperformed(abstractbutton.java:2022) @ javax.swing.abstractbutton$handler.actionperformed(abstractbutton.java:2346) @ javax.swing.defaultbuttonmodel.fireactionperformed(defaultbuttonmodel.java:402) @ javax.swing.defaultbuttonmodel.setpressed(defaultbuttonmodel.java:259)
i have tried methods found in first , second page of google didn't work....
Comments
Post a Comment