Problèmes avec l'utilisation de Gson de pretty-print Chaîne JSON

Quelqu'un pourrait s'il vous plaît suggérer pourquoi ce qui se passe...

J'ai un peu de code pour pretty print certaines JSON. Pour ce faire, j'ai fait l'utilisation de la Gson bibliothèque.

Cependant, tout ainsi fonctionne généralement bien, certains personnages ne semblent pas être affichées correctement. Ici est un simple morceau de code qui illustre le problème:

//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));

La sortie du code ci-dessus est:

{"root":{"value":"xpath('hello')"}}
{
  "root": {
    "value": "xpath(\u0027hello\u0027)"
  }
}

Comment pourrais-je fixer la dessus?

OriginalL'auteur Larry | 2012-06-13