使用jackson json将属性添加到json字符串
I am storing a json string into a text field in mysql. After the insertion, i want to update my json string and add the mysql line id into it with jackson json.
我将json字符串存储在mysql的文本字段中。在插入之后,我想更新我的json字符串并使用jackson json将mysql行id添加到其中。
I have a java String which is in Json format
我有一个JSON格式的java String
{
"thing":"val"
}
I'm looking to add another K/V without writing lines of codes.
我想在不编写代码行的情况下添加另一个K / V.
to finally have this :
最后这个:
{
"thing":"val"
"mysqlId":10
}
I can convert my String to a JsonNode :
我可以将我的String转换为JsonNode:
ObjectMapper mapper = new ObjectMapper();
JsonNode json = mapper.readTree( jsonStr);
Looking to do something like this
希望做这样的事情
json.put("mysqlId",10);
json.toString();
then update in my text field with new json string in mysql
然后在我的文本字段中使用mysql中的新json字符串进行更新
I can't make it. I don't want use many class is there a simple way to do so with jackson?
我做不到。我不想使用很多类是否有一个简单的方法与杰克逊这样做?
1 个解决方案
#1
23
Try casting your JsonNode
to an com.fasterxml.jackson.databind.node.ObjectNode
and then calling put set
(or replace
) on it.
尝试将您的JsonNode转换为com.fasterxml.jackson.databind.node.ObjectNode,然后在其上调用put set(或replace)。
更多相关文章
- 在用户将'n'粘贴复制到文本字段后,如何更新视图模型?
- 如何将带有双引号反斜杠的JSON字符串转换为Javascript对象
- 带有无线电的JavaScript条件字段不起作用
- Javascript正则表达式应该允许空和非空字符串,但它不会
- 如何在onchange()事件后调用的方法中将焦点设置为输入字段?
- 获取拆分字符串数组的最后一个元素
- “错误:路径必须是字符串”(v5.10.0)
- javascript 截取字符串方法汇总
- JavaScript String(字符串对象)