-1

I have json that made of JSONObject that has JSONArray inside. For example,

"value" : {
           "serial":"125",
           "online":"N",
           "menus":[
                   {"menu_name":"name","price":"2000"},{"menu_name":"name","price":"2000"}...
]
}

Can I parse this json to data object using Gson??

EDIT : I saw that example but that was Jsonarray that isn't made of jsonobject.

2
  • I saw that example and that is Jsonarray that isn't made of jsonobject. Commented May 2, 2019 at 2:02
  • I just thinking about just make two data object and handle the object and array separately. Commented May 2, 2019 at 2:03

1 Answer 1

0

sure.

public class Value {
    @SerializedName("serial")
    private String serial;
    @SerializedName("online")
    private String online;
    @SerializedName("menus")
    private Menu[] menus;

    // getters, setters
}
public class Menu {
    @SerializedName("menu_name")
    private String menuName;
    @SerializedName("price")
    private String price;

    // getters, setters
}
Gson gson = new Gson();
Value result = gson.fromJson(jsonObject, Value.class);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.