This is my arraylist
ArrayList<Eat> eatList = gson.fromJson(jsonString, new
TypeToken<ArrayList<Eat>>() {
}.getType());
This is my json: http://www.mocky.io/v2/592fdc32110000ef12b392cc
and this is my model
public class Eat{
private String title,firstItemTitle,firstItemSutitle,
secondItemTitle,secondItemSutitle,
firstItemPrice,secondItemPrice,
firstItemImage,secondItemImage;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFirstItemTitle() {
return firstItemTitle;
}
public void setFirstItemTitle(String firstItemTitle) {
this.firstItemTitle = firstItemTitle;
}
public String getFirstItemSutitle() {
return firstItemSutitle;
}
public void setFirstItemSutitle(String firstItemSutitle) {
this.firstItemSutitle = firstItemSutitle;
}
}
Since your JSON is not a JSON array, but rather a JSON object containing an array, you would need to write a class that contains the ArrayList:
public class EatResponse {
@SerializedName("eat")
private ArrayList<Eat> eatList;
public ArrayList<Eat> getEatList() {
return eatList;
}
}
Then, you just need to parse that from your JSON with a call that would look something like this:
EatResponse response = gson.fromJson(json, EatResponse.class);
ArrayList<Eat> eatList = response.getEatList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With