json拼接转义符

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//转义符替
function escapeReplace(Str) {
    var newStrJson = Str.replace(/\%/g, "%25");
    newStrJson = newStrJson.replace(/\+/g, "%2B");
    newStrJson = newStrJson.replace(/\#/g, "%23");
    newStrJson = newStrJson.replace(/\&/g, "%26");
    newStrJson = newStrJson.replace(/\//g, "%2F");
    newStrJson = newStrJson.replace(/\?/g, "%3F");
    newStrJson = newStrJson.replace(/\=/g, "%3D");
    return newStrJson
}
 
//后台
 public string ToJson(string strjson)
        {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < strjson.Length; i++)
            {
                char c = strjson.ToCharArray()[i]; //strjosn转换为字节数组
                switch (c)
                {
                    case ‘\"‘: sb.Append("\\\""); break;
                    //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();
        }

  

json拼接转义符,布布扣,bubuko.com

json拼接转义符

上一篇:web开端开发分享-css,js入门篇


下一篇:C#利用NPOI导出Excel类(简单版)