我在Retrofit里遇到了一个可以扔的东西
retrofit.RetrofitError: com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 246 path $.suggested.taxonomies[1].payload.scope.我有什么?
我有一个Payload.class,用于从api获取所有数据,有很多嵌套的东西,但是我尝试实现的是LinkedTreeMap<Object, ScopeModel> scope。
Payload.class:
public class Payload {
@SerializedName("product_id")
@Expose
private String productId;
@SerializedName("primary_image")
@Expose
private String primaryImage;
@SerializedName("rating")
@Expose
private String rating;
@SerializedName("review_count")
@Expose
private String reviewCount;
@SerializedName("url")
@Expose
private String url;
@SerializedName("scope")
@Expose //TODO fix this
private LinkedTreeMap<Object, ScopeModel> scope = new LinkedTreeMap<>();
@SerializedName("direct_link")
@Expose
private String directLink;
@SerializedName("keyword")
@Expose
private String keyword;
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getPrimaryImage() {
return primaryImage;
}
public void setPrimaryImage(String primaryImage) {
this.primaryImage = primaryImage;
}
public String getRating() {
return rating;
}
public void setRating(String rating) {
this.rating = rating;
}
public String getReviewCount() {
return reviewCount;
}
public void setReviewCount(String reviewCount) {
this.reviewCount = reviewCount;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public LinkedTreeMap<Object, ScopeModel> getScope() {
return scope;
}
public void setScope(LinkedTreeMap<Object, ScopeModel> scope) {
this.scope = scope;
}
public String getDirectLink() {
return directLink;
}
public void setDirectLink(String directLink) {
this.directLink = directLink;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
}以及我在LinkedTreeeMap中使用的LinkedTreeeMap
public class ScopeModel {
@SerializedName("id")
@Expose
private String id;
@SerializedName("name")
@Expose
private String name;
@SerializedName("type")
@Expose
private String type;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}我为什么要使用LinkedTreeMap?我不明白为什么(我在android中是新手) :D.我的逻辑是:当我将LinkedTreeMap<Object,ScopeModel> scope更改为Payload中的Object scope;时,我在调试器中找到了这样的东西:

正如我所理解的那样,API用我需要的数据返回LinkedTreeMap,因此我试图制作ScopeModel等等。我能用我的代码做什么?
不管怎样,谢谢你,为我的英语道歉!
发布于 2016-02-09 16:08:50
尝试开关
@SerializedName("scope")
@Expose //TODO fix this
private LinkedTreeMap<Object, ScopeModel> scope = new LinkedTreeMap<>();至
@SerializedName("scope")
@Expose //TODO fix this
private ScopeModel scope;https://stackoverflow.com/questions/35296425
复制相似问题