2

How to convert below in Java variable, so i can access it the below response

{
  "Response": {
    "ResponseVal": true,
    "Reason": null
  }
}

I define like this

public class PoliceFineDetailsList {  

    @SerializedName("Response")
    private Object Response;

 
    public Object getResponse() {
        return Response;
    }

    public void setResponse(Object response) {
        Response = response;
    }
}

Image- I am getting object

System.out.println(response.body().getResponse());

But how to access ResponseVal ?

1 Answers1

0

You need to create 2 model classes for this as below

public class PoliceFineDetailsList {

@SerializedName("Response")
@Expose
private Response response;

public Response getResponse() {
return response;
}

public void setResponse(Response response) {
this.response = response;
}

}

and

public class Response {

@SerializedName("ResponseVal")
@Expose
private Boolean responseVal;
@SerializedName("Reason")
@Expose
private Object reason;

public Boolean getResponseVal() {
return responseVal;
}

public void setResponseVal(Boolean responseVal) {
this.responseVal = responseVal;
}

public Object getReason() {
return reason;
}

public void setReason(Object reason) {
this.reason = reason;
}

}

You can access the ResponseVal as below

System.out.println(response.body().getResponse().getResponseVal());
Priyanka
  • 1,791
  • 1
  • 7
  • 12