GSON issue with String

随声附和 提交于 2019-12-02 17:57:40
NINCOMPOOP

The = sign is encoded to \u003d. Hence you need to use disableHtmlEscaping().

You can use

Gson gson = new GsonBuilder().disableHtmlEscaping().create();
String s2 = gson.toJson(hm.toString());

For \/ turning into \\/ issue, the solution is

s2.replace("\\\\", "\\");

Since some people like to nitpick, I'll add the answer to the question (even though it was already answered and chosen as the correct answer) ...

I agree with the chose answer to this question, use the following code:

Gson gson = new GsonBuilder().disableHtmlEscaping().create();
String s2 = gson.toJson(hm.toString());
s2.replace("\\\\", "\\");

@Bajrang Hudda has asked about \n ... I hit this issue recently ... I was able to solve it using:

Gson gson = new Gson();
String json = (gson.toJson(data)).replaceAll("\\\\n", "\\n");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!