【发布时间】:2012-06-13 18:14:24
【问题描述】:
有人能说明为什么会这样吗...
我有一些代码可以漂亮地打印一些 JSON。为此,我使用了Gson library。
但是,虽然这样通常效果很好,但某些字符似乎无法正确显示。下面是一段演示问题的简单代码:
//Creating the JSON object, and getting as String:
JsonObject json = new JsonObject();
JsonObject inner = new JsonObject();
inner.addProperty("value", "xpath('hello')");
json.add("root", inner);
System.out.println(json.toString());
//Trying to pretify JSON String:
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser parser = new JsonParser();
JsonElement je = parser.parse(json.toString());
System.out.println(gson.toJson(je));
以上代码的输出为:
{"root":{"value":"xpath('hello')"}}
{
"root": {
"value": "xpath(\u0027hello\u0027)"
}
}
我该如何解决上述问题?
【问题讨论】: