Gson未能融合符号 [英] Gson failure to conver symbols

查看:137
本文介绍了Gson未能融合符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为 = >使用Gson函数 toJson code>和< 运算符,并且在最后一个字符串中它们被解释为 \\\>



是否有需要添加或照顾的特殊功能?

解决方案

您应禁用HTML转义,以下是一个示例:

  Gson gson1 =新的Gson(); 

String s1 = gson1.toJson(<>);

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

String s2 = gson2.toJson(<>);



:\\\<\\\>



s2:<>


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?

解决方案

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: "<>"

这篇关于Gson未能融合符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆