日期:2014-05-17 浏览次数:20421 次
StringBuilder sb = new StringBuilder(); for (int i = 0; i < json.Length; i++) { char c = json.ToCharArray()[i]; switch (c) { case '\"': sb.Append(""); break; case '\\': sb.Append(""); break; //case '/': // sb.Append(""); break; case '\b': sb.Append(""); break; case '\f': sb.Append(""); break; case '\n': sb.Append(""); break; case '\r': sb.Append(""); break; case '\t': sb.Append(""); break; default: sb.Append(c); break; } } return sb.ToString();
public static string JsonCharFilter(string sourceStr) { sourceStr = sourceStr.Replace("\\", "\\\\"); sourceStr = sourceStr.Replace("\b", "\\\b"); sourceStr = sourceStr.Replace("\t", "\\\t"); sourceStr = sourceStr.Replace("\n", "\\\n"); sourceStr = sourceStr.Replace("\n", "\\\n"); sourceStr = sourceStr.Replace("\f", "\\\f"); sourceStr = sourceStr.Replace("\r", "\\\r"); return sourceStr.Replace("\"", "\\\""); }