[英]Jackson Parsing for json object inside json
我有以下示例數據
{“ data”:{“ detection”:[{“ category”:“ building”,“ coordinates”:{“ xmin”:“ 0.31”,“ ymin”:“ 0.42”,“ ymax”:“ 0.82”,“ xmax“:” 0.89“},”准確性“:” 0.66“}]}}
嘗試在傑克遜解析器中解析數據字段,並為其值創建ObjectCategories類(setter getter)。
@JsonProperty("categories")
private List<ObjectCategory> categories;
@SuppressWarnings("unchecked")
@JsonProperty(DATA)
private void unpackNested(Map<String,Object> data) {
this.categories = (ArrayList<ObjectCategory>) data.get("detection");
}
如果執行上述代碼,則將發生此異常- 無法將 getCategories()。get(0).getAccuracy()轉換為java.util.LinkedHashMap的ObjectCategory
getCategories()。get(0)返回Map值。 如何解析我的ObjectCategory類。
如果最初將其反序列化為映射,則可以轉換該值。
this.categories = objectMapper
.convertValue(data.get("detection"),
new TypeReference<List<ObjectCategory>>() {});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.