下面是我的JSON字符串
{
"addons": {
"BANDWIDTH": [
[
"HSV-A1ABW-C",
"BANDWIDTH",
"vCloud Air",
{
"Monthly": {
"1_99999": [
"219.00",
"HSV-A1ABW-12MT0-C1S",
"vCloud Air - 12 monthly Payments"
]
},
"Prepaid": {
"1_99999": [
"2577.00",
"HSV-A1ABW-12PT0-C1S",
"vCloud Air - Internet Bandwidth Subscription - 12 month Prepaid"
]
}
}
]
]
}
}
public class sample
{
@JsonProperty("addons")
public Addons addons;
//getters and setters
}
public class Addons
{
@JsonProperty("BANDWIDTH")
public List<List<String>> bANDWIDTH;
//getters and setters
}
ObjectMapper objectMapper = new ObjectMapper();
obj = objectMapper.readValue(json,sample.getClass());
当我运行时,我收到以下错误 无法从START_OBJECT标记中反序列化java.lang.String的实例 这里我有数组有一个数组,并在该数组中有一个对象和值,如何使用jackson和java解析它。请帮我 提前致谢
答案 0 :(得分:2)
您已将BANDWIDTH声明为List&lt; List&lt; String&gt;&gt;类型,在你的JSON中,它是一个包含3个字符串的混合列表:
"HSV-A1ABW-C",
"BANDWIDTH",
"vCloud Air"
和一个复杂的对象:
{
"Monthly": {
"1_99999": [
"219.00",
"HSV-A1ABW-12MT0-C1S",
"vCloud Air - 12 monthly Payments"
]
},
"Prepaid": {
"1_99999": [
"2577.00",
"HSV-A1ABW-12PT0-C1S",
"vCloud Air - Internet Bandwidth Subscription - 12 month Prepaid"
]
}
}
因此错误
最简单的&#34;解决方法&#34;您可以使用,只是声明您 BANDWIDTH 属性类型:
List<List<Object>>
让杰克逊将其反序列化为地图和列表的组合。