有人能说一下我错在哪里吗?我有这样的json。
我将其解析为这个类。
Shards班级是什么:
所以我正在使用
最后我得到了“START_ARRAY token”错误。请问有人知道是什么问题吗?
因为我已经尝试了很多方法,但是我从未找到解决方案。
请问该如何修复这个错误?
[{"name":"foo","slug":"foo2","locales":["foo3"],"hostname":"foo4","region_tag":"foo5"},{"name":"foo","slug":"foo2","locales":["foo3"],"hostname":"foo4","region_tag":"foo5"},{"name":"foo","slug":"foo2","locales":["foo3"],"hostname":"foo4","region_tag":"foo5"},{"name":"foo","slug":"foo2","locales":["foo3"],"hostname":"foo4","region_tag":"foo5"}]
我将其解析为这个类。
@JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
@JsonPropertyOrder({
"shards"
})
public class ShardsResponse extends Response{
@JsonProperty("shards")
private List<Shards> shards = new ArrayList<Shards>();
/**
*
* @return
* The shards
*/
@JsonProperty("shards")
public List<Shards> getShards() {
return shards;
}
/**
*
* @param shards
* The shards
*/
@JsonProperty("shards")
public void setShards(List<Shards> shards) {
this.shards = shards;
}
}
Shards班级是什么:
/**
*
* @return
* The locales
*/
@JsonProperty("locales")
public List<String> getLocales() {
return locales;
}
/**
*
* @param locales
* The locales
*/
@JsonProperty("locales")
public void setLocales(List<String> locales) {
this.locales = locales;
}
/**
*
* @return
* The name
*/
@JsonProperty("name")
public String getName() {
return name;
}
/**
*
* @param name
* The name
*/
@JsonProperty("name")
public void setName(String name) {
this.name = name;
}
/**
*
* @return
* The hostname
*/
@JsonProperty("hostname")
public String getHostname() {
return hostname;
}
/**
*
* @param hostname
* The hostname
*/
@JsonProperty("hostname")
public void setHostname(String hostname) {
this.hostname = hostname;
}
/**
*
* @return
* The slug
*/
@JsonProperty("slug")
public String getSlug() {
return slug;
}
/**
*
* @param slug
* The slug
*/
@JsonProperty("slug")
public void setSlug(String slug) {
this.slug = slug;
}
}
所以我正在使用
ObjectMapper.readValue(jsontext, responseclass)
。JSONObject object = new JSONObject(JsonString);
JsonString = "";
Iterator<String> keys= object.keys();
while (keys.hasNext()){
String keyValue = (String)keys.next();
JsonString= JsonString+ object.getString(keyValue);
}
JsonString= JsonString.substring(1, JsonString.length()-1);
Object response = ObjectMapper.readValue(JsonString, ShardsResponse.class);
最后我得到了“START_ARRAY token”错误。请问有人知道是什么问题吗?
因为我已经尝试了很多方法,但是我从未找到解决方案。
请问该如何修复这个错误?