java 将列表添加到 Json ObjectNode
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34240322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 22:38:59 来源:igfitidea点击:
Adding a List to Json ObjectNode
提问by atul mishra
ObjectNode row = Json.newObject();
row.put("0", a);
row.put("1", x);
row.put("2", y);
now I have list
现在我有清单
List<String> list = new ArrayList<String>();
How can I add this to the row?
如何将其添加到行中?
回答by fracz
You can use the putArray
method which creates an ArrayNode
. Then you should fill it with the elements from your list.
您可以使用putArray
创建ArrayNode
. 然后你应该用列表中的元素填充它。
ArrayNode arrayNode = row.putArray("myList");
for (String item : list) {
arrayNode.add(item);
}