これは私の配列リストです
ArrayList<Eat> eatList = gson.fromJson(jsonString, new
TypeToken<ArrayList<Eat>>() {
}.getType());
これは私の 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;
}
}
JSON は JSON 配列ではなく、配列を含むJSONオブジェクトであるため、次を含むクラスを作成する必要がありますArrayList
。
public class EatResponse {
@SerializedName("eat")
private ArrayList<Eat> eatList;
public ArrayList<Eat> getEatList() {
return eatList;
}
}
次に、次のような呼び出しで JSON からそれを解析するだけです。
EatResponse response = gson.fromJson(json, EatResponse.class);
ArrayList<Eat> eatList = response.getEatList();
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加