[英]Jackson Json List inside object
I am having difficulties transforming a Json String into an Object in java using Jackson. 我在使用杰克逊将Json字符串转换为java中的Object时遇到困难。
Model 模型
public class MyList {
public List<MyObj> ads;
}
public class MyObj {
public String id_ad;
}
Data: 数据:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]";
Retrieve code: 检索代码:
ObjectMapper objectMapper = new ObjectMapper();
MyList annonces = objectMapper.readValue(con, MyList.class);
Error: 错误:
Erreur dans getAllAds: com.fasterxml.jackson.core.io.JsonEOFException:
Unexpected end-of-input: expected close marker for Object (start marker at [Source: {"ads":[{"id_ad":"20439"}, {"id_ad":"20449"}]; line: 1, column: 1])
at [Source: {"ads":[{"id_ad":"20439"}, {"id_ad":"20449"}]; line: 1, column: 91]
Questions: 问题:
What is wrong? 怎么了?
Do I need getter/setter for Jackson or public member should work fine? 我需要杰克逊的吸气剂/吸水剂,还是公众成员应该可以正常工作?
Your JSON is incorrect, it is missing a closing curly bracket ( }
) at the end. 您的JSON不正确,它的末尾缺少右花括号(
}
)。
Change from: 更改自:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]";
to: 至:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]}";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.