-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.

하닝야
  • 47
  • 5

1 Answers1

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);
yeahseol
  • 377
  • 1
  • 6