android - Convert JSON array to Java Class Object List -


i have json string comes wfc service. when try convert json array list object, i've got following error :

".jsonmappingexception: can not deserialize instance of java.util.arraylist out of start_object token @ [source: java.io.stringreader@41f27f18; line: 1, column: 1]" 

the java class (card class):

public class card {     public string id;     public string companyid;     public string companyname;     public string fiscalcode;     public string limit;     public string stateid;     public string cardstate;     public string deleted;     public string sold;     public string startdate;     public string invoicestartdate;     public string quantity;     public string value;     public string cardtypeid;     public string cardtype;     public string soldchanged;     public string drivername;     public string vehicleplatenumber;     public string vehicleid;     public string discount;     public string contractid;     public string discountpermonth;     public string productid;     public string productstateid;     public string mail;     public string withoutlimit;     public string contractsold;     public string contractlimit;     public string numberoftransactions;     public string drivernameonly;     public string driversurnameonly; } 

the java code deserialize :

strresponse = responsehandler.handleresponse(response); if (strresponse.contains("credit") || strresponse.contains("debit")) {     objectmapper mapper = new objectmapper();     strresponse= strresponse.replace("\"getcardsresult\":", "");     usercards = mapper.readvalue(strresponse, mapper.gettypefactory().constructcollectiontype(list.class, card.class)); } 

the json string:

{     "getcardsresult":"[{\"id\":3,\"companyid\":1155,\"companyname\":\"test\",\"fiscalcode\":null,\"code\":\"1423127205\",\"limit\":0.000,\"stateid\":1,\"cardstate\":\"activ\",\"deleted\":false,\"sold\":0.000,\"startdate\":\"\/date(1412974800000+0300)\/\",\"invoicestartdate\":\"\/date(-62135596800000+0200)\/\",\"quantity\":null,\"value\":0.0,\"cardtypeid\":1,\"cardtype\":\"credit\",\"soldchanged\":false,\"drivername\":\"\",\"vehicleplatenumber\":\"b 222 art\",\"vehicleid\":null,\"discount\":null,\"contractid\":15,\"discountpermonth\":null,\"productid\":null,\"productstateid\":null,\"mail\":\"\",\"withoutlimit\":true,\"contractsold\":null,\"contractlimit\":null,\"numberoftransactions\":null,\"drivernameonly\":null,\"driversurnameonly\":null},{\"id\":2881,\"companyid\":1155,\"companyname\":\"test\",\"fiscalcode\":null,\"code\":\"test0000\",\"limit\":125.000,\"stateid\":1,\"cardstate\":\"activ\",\"deleted\":false,\"sold\":132.330,\"startdate\":\"\/date(1436130000000+0300)\/\",\"invoicestartdate\":\"\/date(-62135596800000+0200)\/\",\"quantity\":null,\"value\":0.0,\"cardtypeid\":1,\"cardtype\":\"credit\",\"soldchanged\":false,\"drivername\":\"aaa aaa\",\"vehicleplatenumber\":\"aaa\",\"vehicleid\":null,\"discount\":null,\"contractid\":15,\"discountpermonth\":null,\"productid\":null,\"productstateid\":null,\"mail\":\"\",\"withoutlimit\":true,\"contractsold\":null,\"contractlimit\":null,\"numberoftransactions\":null,\"drivernameonly\":null,\"driversurnameonly\":null}]" } 

thanks in advance!

try this:

    try {                      jsonobject jsonobject = null;          yourjsonstring.replace("\\", "");          jsonobject = new jsonobject(yourjsonstring);          string newjsonstring = jsonobject.get("getcardsresult").tostring();          jsonarray jsonmainarr = new jsonarray(newjsonstring);          //now loop json array          (int = 0; < jsonmainarr.length(); ++i) {                               jsonobject rec = jsonmainarr.getjsonobject(i);                               card.set_id(rec.get("id").tostring());                               //....              }                                                               } catch (jsonexception e) {          e.printstacktrace();        }  

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -