如何解决json数据中属性值包含双引号问题,可用以下函数
/// <summary> /// json字符串将属性值中的英文双引号变成中文双引号 /// </summary> /// <param name="strJson">json字符串</param> /// <returns></returns> public string JsonReplaceSign(string strJson) { //获取每个字符 char[] temp = strJson.ToCharArray(); //获取字符数组长度 int n = temp.Length; //循环整个字符数组 for (int i = 0; i < n; i++) { //查找json属性值(:+" ) if (temp[i] == ':' && temp[i + 1] == '"') { //循环属性值内的字符(:+2 推算到value值) for (int j = i + 2; j < n; j++) { //判断是否是英文双引号 if (temp[j] == '"') { //排除json属性的双引号 if (temp[j + 1] != ',' && temp[j + 1] != '}') { //替换成中文双引号 temp[j] = '”'; } else if (temp[j + 1] == ',' || temp[j + 1] == '}') { break; } } else if (temp[j] == '-') { temp[j] = ' '; } else if (true) { // 要过虑其他字符,继续添加判断就可以 } } } } return new String(temp); }
参考地址:https://blog.csdn.net/weixin_34242658/article/details/86022452