Qualcuno potrebbe suggerire perché questo sta accadendo ...Problemi con l'utilizzo di GSON a pretty-print JSON String
ho un po 'di codice per stampare abbastanza alcuni JSON. Per fare questo, sto facendo uso di Gson library.
Tuttavia, sebbene di solito funzioni correttamente, alcuni caratteri non sembrano essere visualizzati correttamente. Ecco un semplice pezzo di codice che illustra il problema:
//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));
L'uscita del codice di cui sopra è:
{"root":{"value":"xpath('hello')"}}
{
"root": {
"value": "xpath(\u0027hello\u0027)"
}
}
Come potrei risolvere quanto sopra?