How to use method in ResponseBody?

  android, java, methods, okhttp

I used ResponseBody from the okhttp3 package and retrofit to make a post-request to my webserver from Android. To send data back (it’s a login system), I tried to create a method to get the data (webserver(php)->app(java in Android Studio)) in a file called ApiResponse.java:

@SerializedName("status")
private String status;

    public String getStatus() {
        return status;
    }

Then I tried this in my MainActivity:

public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.body().getStatus().equals("ok")) { 

It doesn’t recognise getStatus() in ResponseBody ofcourse (Cannot resolve method 'getStatus' in 'ResponseBody'). But how can I get it to recognise it or where do I need to create this method so it recognises it? Or am I doing something incredibly stupid?

Source: Android Questions

LEAVE A COMMENT