我收到服务器的回复:
{"lists":[{"listId":"335","name":"Lists","offers":[{"offerId":"880","startDatetime":"2017-04-01 00:00:00","endDatetime":"2017-11-30 23:59:00","sortPriority":"0","offerName":"bursdag"}]}]}
这是我的课程:
public class List {
private String listId;
private String name;
private java.util.List<Offer> offers = null;
public String getListId() {
return listId;
}
public void setListId(String listId) {
this.listId = listId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public java.util.List<Offer> getOffers() {
return offers;
}
public void setOffers(java.util.List<Offer> offers) {
this.offers = offers;
}
}
package com.example;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
public class Offer {
private String offerId;
private String startDatetime;
private String endDatetime;
private String sortPriority;
private String offerName;
public String getOfferId() {
return offerId;
}
public void setOfferId(String offerId) {
this.offerId = offerId;
}
public String getStartDatetime() {
return startDatetime;
}
public void setStartDatetime(String startDatetime) {
this.startDatetime = startDatetime;
}
public String getEndDatetime() {
return endDatetime;
}
public void setEndDatetime(String endDatetime) {
this.endDatetime = endDatetime;
}
public String getSortPriority() {
return sortPriority;
}
public void setSortPriority(String sortPriority) {
this.sortPriority = sortPriority;
}
public String getOfferName() {
return offerName;
}
public void setOfferName(String offerName) {
this.offerName = offerName;
}
}
我的listId为null,商品中的所有字段均为空。 有什么想法吗?
ListResponse:
public class ListResponse {
List<List> list;
public List<List> getList() {
return list;
}
public void setApps(List<List> list) {
this.list = list;
}
}
答案 0 :(得分:1)
你应该像这样在所有其他变量中使用gson
@SerializedName("listId")
private String listId;