GSON JsonObject getAsString()UTF-8问题

时间:2015-07-01 22:11:23

标签: java gson jsonobject

我有一个json值“test”:“d'exécuter”,当我用gson的getAsString()方法打印它时,它会显示d \u0027exâ“â€?cuter或d'ex ?? cuter。我如何获得“d'exécuter”的实际价值?

String envServices = System.getenv("SERVICES");
JsonObject services = new JsonParser().parse(envServices).getAsJsonObject();
JsonArray arr = (JsonArray) services.get("dev.dev"); //$NON-NLS-1$
if (arr.size() > 0) {
    services = arr.get(0).getAsJsonObject();
    JsonObject credentials = services.get("credentials").getAsJsonObject();
    String val = new String((credentials.get("test").getAsString()).getBytes("UTF-8"));
    String val1 = new String((credentials.get("test").getAsString()));
}

JSON值如下

SERVICES={"dev.dev": [{ "name": "WDS",  "credentials": { "url": "http://test.com", "username": null,"test":"d'exécuter", "password": null } } ] }

0 个答案:

没有答案