-
Notifications
You must be signed in to change notification settings - Fork 59
Open
Labels
Description
在做微信小程序,需要生成子页面的二维码,并且在二维码中需要附带一些参数,例如:page/test/index?q=123
代码如下:
String path = "page/test/index?q=123";
String json = new Gson().toJson(path);
Gson 在转换成JSON的时候, = 号会变成 \u003d,导致生成的二维码不对,无法顺利跳转到具体页面。
出现这个的原因是: Gson会把html标签,转换为Unicode转义字符。
两种解决方法:
方法一:使用 JSONObject
String json = new JSONObject().fromObject(path).toString();
方法二:使用 GsonBuilder
String json = new GsonBuilder().disableHtmlEscaping().create().toJson(path);
;