Java 如何在 Jackson 中将 JSON 字符串解析为 ObjectNode?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24978388/
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
how to parse a JSON string into ObjectNode in Hymanson?
提问by little ali
First of all could anyone explain to me What are differences between ObjectNode and JsonNode, and where they used?
首先,谁能向我解释一下 ObjectNode 和 JsonNode 之间有什么区别,以及它们在哪里使用?
Then if I want to convert a JSON string into ObjectNode what can I do?
那么如果我想将 JSON 字符串转换为 ObjectNode 该怎么办?
采纳答案by Arian Kiehr
You can do:
你可以做:
ObjectMapper mapper = new ObjectMapper();
JsonNode actualObj = mapper.valueToTree("{\"k1\":\"v1\"}")
JsonNode it is a super class of ObjectNode.
JsonNode 它是 ObjectNode 的超类。
You can find the differences in the API.
您可以在 API 中找到差异。