我有以下的JSON字符串,我想讀的是到Java對象,我得到以下錯誤使用地圖的Json傑克遜ObjectMapper到Java對象,得到錯誤
JSON
{"models":[{"id":6002,"publisherName":"AbacusT","active":false}]}
解析Java中
Publisher publisher = new ObjectMapper().readValue(" {\"models\":[{\"id\":6002,\"publisherName\":\"AbacusT\",\"active\":false}]}", Publisher.class);
錯誤
21:21:24,878 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/wad].[springMain]] (http--127.0.0.1-8080-1) Servlet.service() for servlet springMain threw exception: org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "models" (Class com.guthyrenker.wad.core.model.lookup.PublisherLookupItem), not marked as ignorable
at [Source: [email protected]; line: 1, column: 12] (through reference chain: com.guthyrenker.wad.core.model.lookup.PublisherLookupItem["models"])
代碼
// Java class
public class Publisher {
private Integer id;
private String publisherName;
private boolean active;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPublisherName() {
return publisherName;
}
public void setPublisherName(String publisherName) {
this.publisherName = publisherName;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
}
你如何解析該json? 。 – 2014-09-02 04:32:16
出版商出版商=新ObjectMapper()readValue( \t \t \t \t 「{\」 模型\ 「:[{\」 ID \ 「:6002,\」 PUBLISHERNAME \ 「:\」 AbacusT \ 「\」 活性\ 「:false}]}」, \t \t \t \t Publisher.class); – user3157090 2014-09-02 04:35:41
請編輯您的問題。堆棧跟蹤提到'PublisherLookupItem'。那是什麼? – 2014-09-02 04:36:19