0
预计BEGIN_OBJECT但在线串1列1 请帮助我,我得到这个错误预计BEGIN_ARRAY但STRING在第1分1列
我的列表信息类从解析的JSON
ListOffers创建对象的.java
public class ListOffers {
@SerializedName("ListOffers")
@Expose
public List<Offer> offers;
public void setListOffers(List<Offer> offers) {
this.offers = offers;
}
public List<Offer> getListOffers() {
return offers;
}
public ListOffers() {
}
}
public class Offer {
public String username;
@Expose
public String title;
@Expose
public String description;
@Expose
public int discount;
@Expose
public String image1;
@Expose
public String image2;
@Expose
public String image3;
@Expose
public String image4;
public Date expiry_duration;
public Date date_posted;
}
我的JSON:
{"offers":[
{
"username":"zara",
"title":"zara offer",
"description":"zara description",
"discount":"0",
"image1":"",
"image2":"",
"image3":"",
"image4":"",
"expiry_duration":"2014-10-21",
"date_posted":"2014-10-07 04:01:20"
},....
]}
MainActivity代码使用解析JSON GSON .....
try {
// read the server response and attempt to parse it as JSON
Reader reader = new InputStreamReader(content);
GsonBuilder gsonbuilder = new GsonBuilder();
gsonbuilder.setDateFormat("yy-MM-dd hh:mm:ss"); //Format of our JSON dates
Gson gson = gsonbuilder.create();
ListOffers offers = gson.fromJson(reader, ListOffers.class);
content.close();
} catch (Exception ex) {
Log.e(TAG, "Failed to pasre JSON due to: " + ex);
failedLoadingOffers1();
....etc
错误:预期BEGIN_OBJECT但STRING在第1行1列