Fra*_*she 3 android json android-volley
这是我的数组列表
ArrayList<Eat> eatList = gson.fromJson(jsonString, new
TypeToken<ArrayList<Eat>>() {
}.getType());
Run Code Online (Sandbox Code Playgroud)
这是我的 json:http : //www.mocky.io/v2/592fdc32110000ef12b392cc
这是我的模型
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;
}
}
Run Code Online (Sandbox Code Playgroud)
由于您的 JSON 不是 JSON 数组,而是包含数组的 JSON对象,因此您需要编写一个包含以下内容的类ArrayList:
public class EatResponse {
@SerializedName("eat")
private ArrayList<Eat> eatList;
public ArrayList<Eat> getEatList() {
return eatList;
}
}
Run Code Online (Sandbox Code Playgroud)
然后,您只需要使用如下所示的调用从 JSON 中解析它:
EatResponse response = gson.fromJson(json, EatResponse.class);
ArrayList<Eat> eatList = response.getEatList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6393 次 |
| 最近记录: |