public static String StringToJson(String s) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.Length; i++) { char c = s[i]; switch (c) { case ‘\"‘: sb.Append("\\\""); break; case ‘\\‘: sb.Append("\\\\"); break; case ‘/‘: sb.Append("\\/"); break; case ‘\b‘: sb.Append("\\b"); break; case ‘\f‘: sb.Append("\\f"); break; case ‘\n‘: sb.Append("\\n"); break; case ‘\r‘: sb.Append("\\r"); break; case ‘\t‘: sb.Append("\\t"); break; default: sb.Append(c); break; } } return sb.ToString(); }
时间: 2024-12-20 16:19:31