Gson failure to conver symbols

China☆狼群 提交于 2019-12-13 02:26:41

问题


I am using the Gson function toJson for the =, > and < operators, and in the final string they are interpreted as \u003e.

Is there a special feature I need to add or take care of?


回答1:


You should disable HTML escaping, here is a sample that illustrates it:

Gson gson1 = new Gson();

String s1 = gson1.toJson("<>");

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

String s2 = gson2.toJson("<>");

s1: "\u003c\u003e"

s2: "<>"



来源:https://stackoverflow.com/questions/17092044/gson-failure-to-conver-symbols

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!