欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

json解析时遇到英文双引号报错的解决方法

程序员文章站 2023-12-03 10:00:34
有时解析json时,会碰到里面带有英文的双引号,导致解析错误,可以将json进行转义,一下: public static string htmlescape(...

有时解析json时,会碰到里面带有英文的双引号,导致解析错误,可以将json进行转义,一下:

public static string htmlescape(string input) {
if(isempty(input)){
  return input;
}
input = input.replaceall("&", "&");
input = input.replaceall("<", "<");
input = input.replaceall(">", ">");
input = input.replaceall(" ", " ");
input = input.replaceall("'", "'");  //ie暂不支持单引号的实体名称,而支持单引号的实体编号,故单引号转义成实体编号,其它字符转义成实体名称
input = input.replaceall("\"", """); //双引号也需要转义,所以加一个斜线对其进行转义
input = input.replaceall("\n", "<br/>"); //不能把\n的过滤放在前面,因为还要对<和>过滤,这样就会导致<br/>失效了
return input;
}

以上这篇json解析时遇到英文双引号报错的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。