java - Unable to fetch json object and array in Retrofit 2 -


i'm trying parse json api http://badiyajobs.com/apis/v1/roles
but response.issuccess returning false
modal class is,

package arpit.retrodemo;   import java.util.list; import java.util.arraylist;  public class modal {                 private list<rolesentity> roles = new arraylist<>();      public void setroles(list<rolesentity> roles) {         this.roles = roles;     }      public list<rolesentity> getroles() {         return roles;     }      public static class rolesentity {         private string id;         private string role;         private string description;         private string icon_url;         private string created_at;         private string updated_at;          public void setid(string id) {             this.id = id;         }          public void setrole(string role) {             this.role = role;         }          public void setdescription(string description) {             this.description = description;         }          public void seticon_url(string icon_url) {             this.icon_url = icon_url;         }          public void setcreated_at(string created_at) {             this.created_at = created_at;         }          public void setupdated_at(string updated_at) {             this.updated_at = updated_at;         }          public string getid() {             return id;         }          public string getrole() {             return role;         }          public string getdescription() {             return description;         }          public string geticon_url() {             return icon_url;         }          public string getcreated_at() {             return created_at;         }          public string getupdated_at() {             return updated_at;         }     } } 


sample json is,

{"roles":[     {       "id":"1",       "role":"retail sales executive",       "description":"as sales assistant....",       "icon_url":"",       "created_at":"2015-10-02 12:03:03",       "updated_at":null     }   ]  } 


apiservice.java is,

package arpit.retrodemo;  import retrofit.call; import retrofit.http.get;  public interface apiservice {     @get("/roles")     call<modal> getdetails(); } 


mainactivity.java is,

package arpit.retrodemo;  import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.util.log;   import java.util.arraylist; import java.util.iterator; import java.util.list;  import retrofit.call; import retrofit.callback; import retrofit.gsonconverterfactory; import retrofit.response; import retrofit.retrofit;  public class mainactivity extends appcompatactivity {      private static final string endpoint = "http://badiyajobs.com/apis/v1";     private apiservice service;     private modal mod;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          retrofit retrofit = new retrofit.builder()                 .addconverterfactory(gsonconverterfactory.create())                 .baseurl(endpoint)                 .build();         service = retrofit.create(apiservice.class);         call<modal> userlist = service.getdetails();         userlist.enqueue(new callback<modal>() {             @override             public void onresponse(response<modal> response) {                 if(response.issuccess()){                     log.d("findres", response.body().tostring());                 }else{                     log.d("find", "something wrong! " + response.errorbody().tostring());                 }             }              @override             public void onfailure(throwable t) {                 log.d("finderror", t.getmessage());             }         });     } } 


here i'm getting following on logcat,

d/find: wrong! com.squareup.okhttp.responsebody$1@52715c98 


instead of string representation of response.body()

you need following:

public interface apiservice {     @get("roles") /*removed / here */     call<modal> getdetails(); }  private static final string endpoint = "http://badiyajobs.com/apis/v1/"; /* added / here */ 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -