Reputation: 281
What is the error here? I am not able to parse it to the list.
I am trying to get json from this file using jsonUrl.
Please let me know where am i making this mistake.
"recommended":[
{
"thumbnail":"http://farm8.staticflickr.com/7390/11919320035_1f6dd4da79_z.jpg",
"itemname":"Chilli Babycorn",
"itemtype":"veg",
"price":"45"
},
{
"thumbnail":"http://res.cloudinary.com/dhdglilcj/image/upload/v1455448132/foodonz/dishes/d7.jpg",
"itemname":"Honey Chilli Potato",
"itemtype":"veg",
"price":"90"
}
],
"veg starters":[
{
"itemname":"Paneer Tikka",
"itemtype":"veg",
"price":"110"
},
{
"itemname":"Aloo Tandoori",
"itemtype":"veg",
"price":"60"
}
]
}
This is the itemsMenus class
Please relate it with the above code.
public class ItemsMenu {
private String thumbnail;
private String itemname;
private String price;
public String getItemtype() {
return itemtype;
}
public void setItemtype(String itemtype) {
this.itemtype = itemtype;
}
private String itemtype;
private String quantity="0";
public String getThumbnail() {
return thumbnail;
}
public void setThumbnail(String thumbnail) {
this.thumbnail = thumbnail;
}
public String getQuantity() {
return quantity;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getItemname() {
return itemname;
}
public void setItemname(String itemname) {
this.itemname = itemname;
}
}
Upvotes: 1
Views: 1161
Reputation: 1731
Simply use http://www.jsonschema2pojo.org/ to convert any type of json to write model. As your jsons seems to be simple and doesn't require to use TypeToken. And Further use
new Gson().fromJson(jsonString,model.class)
You will get the desired list.
Upvotes: 2
Reputation: 6712
You can convert json
string direct to List<ItemsMenu>
List<ItemsMenu> list = new Gson().fromJson(jsonString, new TypeToken<List<ItemsMenu>>(){}.getType());
Upvotes: 1