S
S
Stanislav2017-04-29 17:08:10
Java
Stanislav, 2017-04-29 17:08:10

How to get the value of an object in the model?

I don’t understand how to pull out the width value
There is an object

{
    size: {
        width: 100,
        height: 120
    }
}

I am writing a model
public class Document {
    @SerializedName("size")
    @Expose
    private JSONObject size;

    public JSONObject getSize() {
        return size;
    }

}

Get object data
Document document = new Gson().fromJson(json, Document.class);

Log.d(TAG, "size: " + document.getSize()); // size: {}

Ideally, I would like to get the width in the model itself .getSizeWidth()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav, 2017-04-29
@ms-dred

Why is everything so bold)
I had to create another model Size.java

public class Size {

    @SerializedName("width")
    @Expose
    private String width;
    @SerializedName("height")
    @Expose
    private String height;

    public String getWidth() {
        return width;
    }

    public String getHeight() {
        return height;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question