0
我在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中的newbiew):D。 我的邏輯是:當我在Payload
改變LinkedTreeMap<Object,ScopeModel> scope
到Object scope;
我在那件事調試發現:
我的理解API返回我LinkedTreeMap
與我需要的數據,因爲我嘗試做ScopeModel
等我能用我的代碼做什麼?
無論如何,謝謝你,對不起我的英語!
我不知道來回答你,因爲我不習慣LikedTreeMap。你可以添加你的json文件嗎? –
@RenaudFavier調試器輸出不夠? – VLeonovs
我不明白你的json是什麼樣的,我懷疑LikedTreeMap是你需要的正確類型 –