我就废话不多说了,大家还是直接看代码吧~
encodeURIComponent('\n')
"%0A"
encodeURIComponent('\\')
"%5C"
encodeURIComponent('/')
"%2F"
encodeURIComponent(',') "%2C"
encodeURIComponent('\'')
%27
encodeURIComponent("\"") "%22"
data = json;
data = data.Replace("\\", "%5C").Replace("\n", "%0A");//.Replace("/","%2F");
.Replace(",", "%2C").Replace("'", "%27").Replace("\\", "%5C").Replace("\n", "%0A")
encodeURIComponent("\"")
"%22"
encodeURIComponent('\')
"%5C"
补充:C#中Xml特殊字符的处理
以下是几个特殊字符的对应实体。
|
< |
< |
小于号 |
|
> |
> |
大于号 |
|
& |
& |
和 |
|
' |
‘ |
单引号 |
|
" |
“ |
双引号 |
在C#中,直接调用C#提供的方法,保存之后就会自动将特殊字符转为对应实体:
string s =System.Security.SecurityElement.Escape(s);
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。如有错误或未考虑完全的地方,望不吝赐教。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

评论(0)