我在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;
}
}
我在ScopeModel
中使用的和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
中将Object scope;
更改为Payload
时:
据我所知,API会向我返回LinkedTreeMap
我需要的数据,因此我尝试制作ScopeModel
等等。我的代码怎么办?
无论如何,谢谢你,对不起我的英语!
答案 0 :(得分:1)
尝试切换
@SerializedName("scope")
@Expose //TODO fix this
private LinkedTreeMap<Object, ScopeModel> scope = new LinkedTreeMap<>();
到
@SerializedName("scope")
@Expose //TODO fix this
private ScopeModel scope;