更快的XML Jackson:删除双引号 [英] Faster XML Jackson: Remove double quotes
本文介绍了更快的XML Jackson:删除双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下json:
{"test":"example"}
我使用Faster XML Jackson中的以下代码。
I use the following code from Faster XML Jackson.
JsonParser jp = factory.createParser("{\"test\":\"example\"}");
json = mapper.readTree(jp);
System.out.println(json.get("test").toString());
输出:
"example"
Jackson中是否有设置删除双引号?
Is there a setting in Jackson to remove the double quotes?
推荐答案
那么,当你 .get(test)
是 JsonNode
,它碰巧是 TextNode
;当你 .toString()
它,它将返回 TextNode
的字符串表示,这就是你获得它的原因结果。
Well, what you obtain when you .get("test")
is a JsonNode
and it happens to be a TextNode
; when you .toString()
it, it will return the string representation of that TextNode
, which is why you obtain that result.
你想要的是:
.get("test").textValue();
这将返回JSON字符串本身的实际内容(所有内容都未转义等等)。
which will return the actual content of the JSON String itself (with everything unescaped and so on).
请注意,如果 JsonNode
不是 <$ c $,这将返回null c> TextNode 。
这篇关于更快的XML Jackson:删除双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文