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 '': sb.Append("\b"); break; case 'f': sb.Append("\f"); break; case ' ': sb.Append("\n"); break; case ' ': sb.Append("\r"); break; case ' ': sb.Append("\t"); break; default: sb.Append(c); break; } } return sb.ToString(); }