下面提到的是json字符串resultString {
{
"imageMaps": [{
"crc": "c2c4",
"flags": "0",
"length": "117384",
"index": 1,
"version": "1.1.90ea",
"status": ""
}, {
"crc": "7601",
"flags": "8",
"length": "117592",
"index": 2,
"version": "1.1.90ed",
"status": ""
}],
"complete": true,
"nextBootImageVersion": "",
"lastKnownGoodImageVersion": "1.1.90ed",
"runningImageVersion": "1.1.90ed"
}
我希望将其转换为A类的对象。
公共类A {
private boolean complete;
private String message;
private String lastKnownGoodImageVersion;
private String nextBootImageVersion;
private String runningImageVersion;
private Map<String, B> imageMaps;
private List<B> images;
private MacID macId;
}
我正在尝试使用代码将json转换为A类的对象:
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
a a = objectMapper.readValue(resultString,A.class);
B类的代码是:
public static class B{
public String version;
public int flags;
public int crc;
public long length;
public String index;
public String status;
}
但是出现异常:com.fasterxml.jackson.databind.JsonMappingException:无法从START_ARRAY令牌中反序列化java.util.LinkedHashMap实例
答案 0 :(得分:1)
您在类中将属性imageMaps
声明为Map<String, B>
,但在JSON imageMaps
中则是一个B数组。如果将imageMaps
更改为images
在您的JSON中。