java - How to access the String value inside the object using retrofit 3 -


how access string result inside object response using retrofit

{  "response": {   "result": "success",   "data": "added successfully"  } } 

my pojo class

public class responselist {

@serializedname("response") private response response;  public response getresponse() {     return response; }  public void setresponse(response response) {     this.response = response; }  public class responseinr {      @serializedname("result")     private string result;     @serializedname("data")     private string data;      public string getresult() {         return result;     }      public void setresult(string result) {         this.result = result;     }      public string getdata() {         return data;     }      public void setdata(string data) {         this.data = data;     }  } 

}

//post data

map data = new hashmap<>();

    data.put("data_type", "postcompliant");      data.put("compliant_name", "map1");      data.put("location", "map_cbe");      data.put("description", "map_desc");      data.put("compliant_status", "map_true");      data.put("user_id", "map_id");      call<responselist> call3 = apiinterface.docreateuserwithfieldrespon(data);     call3.enqueue(new callback<responselist>() {         @override         public void onresponse(call<responselist> call, response<responselist> response) {              system.out.println("test" + response.body().tostring());              responselist userlist = response.body();              string result = userlist.result;             string data = userlist.data;              responsetext.settext(result + "\t" + data);          }          @override         public void onfailure(call<responselist> call, throwable t) {              log.d("error", "" + t.getmessage());             call.cancel();         }     }); 

try

public class responselist {      @serializedname("response")     private responseinr response;      public responseinr getresponse() {         return response;     }      public void setresponse(responseinr response) {         this.response = response;     }      public class responseinr {          @serializedname("result")         private string result;         @serializedname("data")         private string data;          public string getresult() {             return result;         }          public void setresult(string result) {             this.result = result;         }          public string getdata() {             return data;         }          public void setdata(string data) {             this.data = data;         }      }  } 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -