java - com.google.gson.JsonSyntaxException: Expected BEGIN_ARRAY but was STRING -


i facing error in parsing json data :

 expected begin_array string @ line 1 column 1156 

i could'nt find solution. json data :

{     "project": [         {             "abbreviation": "abd",             "customer": "customer1",             "description": "description1",             "icon": "ivborw0kggoaaaansuheugaaabaaaaaqcayaaaaf8/9haaac4uleqvr42sxtxuhtyrgh8nnnxktdmplrpltqalgxzlb4hcc6c8vyyjertbconljiqqmotqmyckuxdhnegshyuvxcj81n58dco+ropt3c2dnowtubespuv6pzx1u3xftaj4f3gf/zxl0e8d+loqgew+rkvnnowmi22h6ytx4bhrtlst2xskhuqr8vkmkfys5i8y5lhgembyex8xhpp3cicxpoevfcf3//lrvanadrabk0wu0wnu632xdk8x3e1mxcszr1cez7ewgm1iedqewyasw6ycmajqqbqgde5/n98hq9lnvtppxoj8uwdext9lujiymthmlkiumxuvgxq1kiw5doegufocrjmyiiiegkap7nwxecwjaf3+/hysoknc7xxttuda1hnbrjzuvx+bpi8thisbh0+xcwfaohyiuqyans0a2p2wgxyw6gwdyymo7vexq9nur5qspecndgw0geq6x0mqa24meqzwpvwhiwxzed7q6crecibl2xyo2s+drzogcegncbilmfk3e8fyslxiwwn13f8vmald27gsu+jwydfbdclcrsvtjmfemyqdym2auzcredgnwbij02a79w/wtmlomyqz74y6zypwzmvmdi9vifqjngrk0cjz5omiozi8vb7kklruvk8rblbpm/dhjz1yx1obbsuvhd5tt8k3wqgb43ftpdr3hlyxew6o/cwl8a280jwlydh+xghdbnwxa+lmopkshvnalnsyycrtlyw+swtqs9kbzmkrahpog+uwh7w1g4m/lgv2uh2czdwj0bqzoosmd+rdptixslgjdwnwly7tjwjdgmtrfvboek9c9b7fmnx2j0u67oehri9d6wiavtcjh4jevktbkdxjiusrpu0a9nfj2afnhefibsugvcjk6fobunqbq0sf2ax6ipyyy7yrpirvpzzhdfdtmjycv7k/o3+lofnfpiya4kgdlxqua2l8lplr9ps/nnz/gdnpctqcpv7vgaaaaasuvork5cyii=",             "name": "projectname1",             "plannedenddate": "2012-05-25t00:00:00+01:00",             "plannedstartdate": "2012-05-23t00:00:00+01:00",             "projectstatus": {                 "name": "opened"             },             "realenddate": "2012-05-25t00:00:00+01:00",             "realstartdate": "2012-05-23t00:00:00+01:00"         }     ] } 

i convert image byte array :

public static byte[] converttobytearray(string path) {           byte[] imageinbyte = null;         try{              bufferedimage originalimage =                                        imageio.read(new file(path));              bytearrayoutputstream baos = new bytearrayoutputstream();             imageio.write( originalimage, "png", baos );             baos.flush();             imageinbyte = baos.tobytearray();              baos.close();              }catch(ioexception e){                 system.out.println(e.getmessage());             }         return imageinbyte;     } 

and i'm converting icon byte array bitmap :

bitmap bm = bitmapfactory.decodebytearray(project.geticon(), 0,         project.geticon().length); displaymetrics dm = new displaymetrics();  holder.imageprojet.setminimumheight(dm.heightpixels); holder.imageprojet.setminimumwidth(dm.widthpixels); holder.imageprojet.setimagebitmap(bm); 

the code deserialize json response :

gson gson = new gsonbuilder().setdateformat(                 "yyyy-mm-dd't'hh:mm:ssz").create();          final projectcontainer container = gson.fromjson(resultat,                 projectcontainer.class);         final listview lv = (listview) findviewbyid(r.id.list);          /**          * updating parsed json data listview          * */         adaptateur = new projectadapter(projectactivity.this,                 r.layout.ligne_project, container); 

this projectcontainer class :

  public class projectcontainer {         @serializedname("project")         list<project> projects ;          public list<project> getprojects() {             return projects;         }          public void setprojects(list<project> projects) {             this.projects = projects;         }     } 

and project class :

public class project implements serializable {      private static final long serialversionuid = 1l;     @serializedname("projectstatus")     private projectstatus projectstatus;     @serializedname("name")     private string name;     @serializedname("description")     private string description;     @serializedname("abbreviation")     private string abbreviation;     @serializedname("customer")     private string customer;     @serializedname("plannedstartdate")     private date plannedstartdate;     @serializedname("plannedenddate")     private date plannedenddate;     @serializedname("realstartdate")     private date realstartdate;     @serializedname("realenddate")     private date realenddate;     @serializedname("isdeleted")     private boolean isdeleted;     @serializedname("icon")     private byte[] icon;       public project() {     }      public project(string name, string description, string abbreviation,             string customer, date plannedstartdate, date plannedenddate,             projectstatus projectstatus, date realstartdate, date realenddate) {         this.name = name;         this.description = description;         this.abbreviation = abbreviation;         this.plannedstartdate = plannedstartdate;         this.plannedenddate = plannedenddate;         this.projectstatus = projectstatus;         this.realstartdate = realstartdate;         this.realenddate = realenddate;         this.customer = customer;      }      public string tostring() {         return name;     }      public projectstatus getprojectstatus() {         return this.projectstatus;     }      public void setprojectstatus(projectstatus projectstatus) {         this.projectstatus = projectstatus;     }      public string getname() {         return this.name;     }      public void setname(string name) {         this.name = name;     }      public string getdescription() {         return this.description;     }      public void setdescription(string description) {         this.description = description;     }      public string getabbreviation() {         return this.abbreviation;     }      public void setabbreviation(string abbreviation) {         this.abbreviation = abbreviation;     }      public date getplannedstartdate() {         return this.plannedstartdate;     }      public void setplannedstartdate(date plannedstartdate) {         this.plannedstartdate = plannedstartdate;     }      public date getplannedenddate() {         return this.plannedenddate;     }      public void setplannedenddate(date plannedenddate) {         this.plannedenddate = plannedenddate;     }      public date getrealstartdate() {         return this.realstartdate;     }      public void setrealstartdate(date realstartdate) {         this.realstartdate = realstartdate;     }      public date getrealenddate() {         return this.realenddate;     }      public void setrealenddate(date realenddate) {         this.realenddate = realenddate;     }       public byte[] geticon() {         return this.icon;     }      public void seticon(byte[] icon) {         this.icon = icon;     }      public string getcustomer() {         return this.customer;     }     public void setcustomer(string customer) {         this.customer= customer;     } } 

i appreciate if can me solve problem. in advance

the exception thrown when try parse field "icon", because in json response there string, , try parse byte[].

since in class, icon array of bytes, when tries parse field "icon" says "expected array", in json response "icon" not array (there's nothing surrounded [ ]), says "but string"...


edit: said, in order fix it, easiest way in opinion change type of icon string parse correctly, , conversion byte[] somewhere else... example can have method in class, let's public byte[] geticonasbytearray() {...}, conversion.

otherwise, , elegant solution, need write custom deserializer.


Comments

Popular posts from this blog

Change php variable from jquery value using ajax (same page) -

Pull out data related to my apps from Android Play Store and iOS App Store -

How can I fetch data from a web server in an android application? -