Gson库的输出toJson方法中的Json不正确

时间:2017-12-11 12:17:08

标签: java json gson marshalling

我使用方法toJson从对象生成json。将对象转换为json视图时遇到错误。

    SingnUpRq singnUpRq = new SingnUpRq("lsjdflkdjslfk", "ZCqKckIpwvxtLFZz3TlUln5RqUpEB5U43imi7PSYv6UBY/bLvKQBSDIxXR5cAKnK+CU+UiyBB998fRJRvGJJDw==");

    String postBody = gson.toJson(singnUpRq);

    postBody (problem with last symbols == :{"DeviceId":"lsjdflkdjslfk","RefreshToken":"ZCqKckIpwvxtLFZz3TlUln5RqUpEB5U43imi7PSYv6UBY/bLvKQBSDIxXR5cAKnK+CU+UiyBB998fRJRvGJJDw\u003d\u003d"}

为什么会出现这个问题? 我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

我在这里找到了解决方案: https://github.com/google/gson/issues/203

而是使用构造函数new Gson(),需要使用

Gson gson = new GsonBuilder().disableHtmlEscaping().create();