Jackson Json List里面的对象 [英] Jackson Json List inside object
本文介绍了Jackson Json List里面的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在使用Jackson将Json String转换为java中的Object时遇到了困难。
I am having difficulties transforming a Json String into an Object in java using Jackson.
模型
public class MyList {
public List<MyObj> ads;
}
public class MyObj {
public String id_ad;
}
数据:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]";
检索代码:
ObjectMapper objectMapper = new ObjectMapper();
MyList annonces = objectMapper.readValue(con, MyList.class);
错误:
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]
问题:
-
出了什么问题?
What is wrong?
我是否需要杰克逊的getter / setter或公共成员应该工作
罚款?
Do I need getter/setter for Jackson or public member should work fine?
推荐答案
你的JSON不正确,它丢失了结尾的大括号(}
)。
Your JSON is incorrect, it is missing a closing curly bracket (}
) at the end.
改变自:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]";
to:
String con = "{\"ads\":[{\"id_ad\":\"20439\"}, {\"id_ad\":\"20449\"}]}";
这篇关于Jackson Json List里面的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文