JasonHelper.Escape 转换字符串为jason格式代码
JasonHelper
public static class JasonHelper
{
public static string Escape(string s)
{
if (s == null)
return null;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.Length; i++)
{
char ch = s[i];
switch (ch)
{
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;
case '/':
sb.Append("\\/");
break;
default:
sb.Append(ch);
break;
}
}//for
return sb.ToString();
}
}
public static class JasonHelper
{
public static string Escape(string s)
{
if (s == null)
return null;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.Length; i++)
{
char ch = s[i];
switch (ch)
{
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;
case '/':
sb.Append("\\/");
break;
default:
sb.Append(ch);
break;
}
}//for
return sb.ToString();
}
}