【发布时间】:2017-08-11 20:34:25
【问题描述】:
我已经使用http://www.jsonschema2pojo.org/ 生成了我的 POJO,现在我想解析我的 JSONResponse 格式:
[
{
"id":1,
"name":"xyz",
"rxg":5,
"img":"xyz.jpg"
},
{
"id":2,
"name":"abc",
"rxg":9,
"img":"abc.jpg"
},
{ },
{ }
这就是我不知道如何进行的地方:
Call<List<MyList>> call = apiInterface.doGetListResources();
call.enqueue(new Callback<List<MyList>>() {
@Override
public void onResponse(Call<List<MyList>> call,
Response<List<MyList>> response) {
// How to proceed ahead? I'm completely stuck here
}
这是我的模型类:
公共类 MyList 实现 Parcelable {
@SerializedName("id")
@Expose
public int id;
@SerializedName("name")
@Expose
public String name;
@SerializedName("rxg")
@Expose
public int rxg;
@SerializedName("image")
@Expose
public String img;
public final static Parcelable.Creator<MyList> CREATOR = new Creator<MyList>() {
@SuppressWarnings({
"unchecked"
})
public MyList createFromParcel(Parcel in) {
MyList instance = new MyList();
instance.id = ((int) in.readValue((int.class.getClassLoader())));
instance.name = ((String) in.readValue((String.class.getClassLoader())));
instance.rxg = ((int) in.readValue((int.class.getClassLoader())));
instance.img = ((String) in.readValue((String.class.getClassLoader())));
return instance;
}
public MyList[] newArray(int size) {
return (new MyList[size]);
}
};
/**
* No args constructor for use in serialization
*/
public MyList() {
}
/**
* @param id
* @param rxg
* @param name
* @param img
*/
public MyList(int id, String name, int rxg, String img) {
super();
this.id = id;
this.name = name;
this.rxg = rxg;
this.img = img;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRxg() {
return rxg;
}
public void setRxg(int rxg) {
this.rxg = rxg;
}
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public void writeToParcel(Parcel dest, int flags) {
dest.writeValue(id);
dest.writeValue(name);
dest.writeValue(rxg);
dest.writeValue(img);
}
public int describeContents() {
return 0;
}
}
这是我第一次尝试改造,所以请多多包涵。非常感谢您的帮助。我试图在这里研究类似的问题:https://stackoverflow.com/a/39774297/5770629 但无法采取进一步措施。
【问题讨论】: