java - Gson error expected begin_object but was string at line 1 column 1 path $ -


i hope give me hand on gson issue can't solve. quiet common apparently since found many topic on subject, didn't manage use answers.

i have error :

com.google.gson.jsonsyntaxexception: java.lang.illegalstateexception: expected begin_object string @ line 1 column 1 path $

here json :

{"valeurs":[{"ident":"1","lien":"r8wzdmerigo","categorie":"1"},{"ident":"2","lien":"neqgjgz08fw","categorie":"2"}],"success":1}  

then pojo:

public class gitmodel {   @serializedname("ident") @expose private int ident;  @serializedname("lien") @expose private string lien;  @serializedname("categorie") @expose private int categorie;     public int getident() {return ident;}   public string getlien() {     return lien; }    public int getcategorie() {     return categorie; } 

}

and in main activity :

restadapter restadapter = new restadapter.builder()                     .setendpoint(api)                     .build();              gitapi git = restadapter.create(gitapi.class);               git.getfeed("affichage_bd.php", new callback<gitmodel>() {                 @override                 public void success(gitmodel gitmodel, response response) {                     tv.settext("numero categorie :" + gitmodel.getcategorie() + "\nlien :" + gitmodel.getlien() + "\nidentification :" + gitmodel.getident());                 }                  @override                 public void failure(retrofiterror error) {                     tv.settext(error.getmessage());                 }             });         }     }); 

could please tell me what's going on?

you missing level. pojo set in callback<> should :

public class mymodel {   list<gitmodel> valeurs;    public list<gitmodel> getvaleurs()    {      return valeurs;    } } 

edit:
should save mymodel class somewhere in project, , change interface to:

public interface gitapi {     @get("/users/{user}")     public void getfeed(@path("user") string user, callback<mymodel> mymodel);  } 

so in mainactivity:

git.getfeed("affichage_bd.php", new callback<mymodel>() {                 @override                 public void success(mymodel mymodel, response response) {                     list<gitmodel> valeurs = mymodel.getvaleurs();                     //  here can iterate through elements on list                 }                  @override                 public void failure(retrofiterror error) {                     tv.settext(error.getmessage());                 }             }); 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -