简体   繁体   English

使用java中的jackson将json数组作为值添加到json键中

[英]Adding the json array as a value to a json key using jackson in java

I'm getting a result from mongo db as我从 mongo db 得到一个结果

 [{"k1":"v1"},{"k2":"v2"}]. 

How to convert this result into如何将此结果转换为

{"key" : [{"k1":"v1"},{"k2":"v2"}] } 

using jackson.使用杰克逊。

Make a separate class 'Key' with those members and in your main class have an array of Keys like使用这些成员创建一个单独的类“Key”,并且在您的主类中有一个 Keys 数组,例如

Key keys[];

then use the ObjectMapper to parse the values from mongo and write them back again to get the output.然后使用 ObjectMapper 解析来自 mongo 的值并再次将它们写回以获取输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM