Gson库的toJson方法输出不正确Json
Incorrect Json in output toJson method of Gson library
我使用方法 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"}
为什么会出现这个问题?
我该如何解决这个问题?
我在这里找到了解决方案:
https://github.com/google/gson/issues/203
改为使用构造函数new Gson()
,需要使用
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
我使用方法 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"}
为什么会出现这个问题? 我该如何解决这个问题?
我在这里找到了解决方案: https://github.com/google/gson/issues/203
改为使用构造函数new Gson()
,需要使用
Gson gson = new GsonBuilder().disableHtmlEscaping().create();