android - Using Gson to parse string to object. Boolean value is always false -


i fecht json-string server:

{"erfolgreich":"true","id":"14"} 

when call

//result string above msgserver = gson.fromjson(result, msgspielererstellensa.class); 

the boolean false...

what doing wrong?

here msgspielererstellensa

public class msgspielererstellensa {      private long id;     private boolean iserfolgreich;      public msgspielererstellensa(long id, boolean iserfolgreich) {         super();         this.id = id;         this.iserfolgreich = iserfolgreich;     }       public boolean iserfolgreich() {         return iserfolgreich;     }      public void seterfolgreich(boolean iserfolgreich) {         this.iserfolgreich = iserfolgreich;     }      public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     }   } 

because correct name boolean field erfolgreich, not iserfolgreich. please use following class:

public class msgspielererstellensa {      private long id;     private boolean erfolgreich;      public msgspielererstellensa(long id, boolean iserfolgreich) {         this.id = id;         this.erfolgreich = iserfolgreich;     }       public boolean iserfolgreich() {         return erfolgreich;     }      public void seterfolgreich(boolean iserfolgreich) {         this.erfolgreich = iserfolgreich;     }      public long getid() {         return id;     }      public void setid(long id) {         this.id = id;     } } 

but if don't want rename field, can use @serializedname("erfolgreich") annotation on it


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -