Retrofit Gson反序列化字符串特殊字符

时间:2015-10-28 17:40:44

标签: android json gson retrofit

我有那个json

[
  {
    TITLE: "Yoy’s Child"
  },
    TITLE: "Look at me – Stop looking"
  }
]

我使用retrofit和gson,结果是

Yoy’s Child
Look at me – Stop looking

问题在于编码特殊字符。这是我的代码

GsonBuilder gsonBuilder = new GsonBuilder()
            .excludeFieldsWithoutExposeAnnotation()
            .registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {
                public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
                    return new Date(json.getAsJsonPrimitive().getAsLong());
                }
            });

    gson = gsonBuilder.create();

    RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(WEB_URL)
            .setConverter(new GsonConverter(gson))
            .build();

    apiService = restAdapter.create(APIService.class);

2 个答案:

答案 0 :(得分:2)

尝试将disableHtmlEscaping命令添加到GsonBuilder构造函数。

GsonBuilder gsonBuilder = new GsonBuilder().disableHtmlEscaping();

答案 1 :(得分:0)

我解决了。我调试了应用程序,发现返回json有符号问题。我所要做的只是将json编码为UTF-8。