Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get JSONObject from retrofit2 response

How to get in retrofit2 unknown JSON object from response object like this request (with OkHttp3):

Observable<Response<MyResponseObject>> apiCall(@Body body);

MyResponseObject look like this:

public class MyResponseObject {

    @SerializedName("title")
    public String title;

    @SerializedName("info")
    public JSONObject info;

    @SerializedName("question_id")
    public String questionId;

   }

I want to get

JSONObject info

like a regular object.

like image 990
Moti Avatar asked Jan 18 '26 13:01

Moti


1 Answers

You need to create another class (Info):

public static class Info {

    @SerializedName("description")
    public String mDescription;
    @SerializedName("preview_image")
    public String mPreviewImage;

}

and in MyResponseObject:

@SerializedName("info")
public Info info;
like image 69
user3686440 Avatar answered Jan 21 '26 04:01

user3686440



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!