zoukankan      html  css  js  c++  java
  • C# 去除json字符串key引号

    采用正则表达式去除;

    方法

            /// <summary>
            /// 去除json key双引号
            /// </summary>
            /// <param name="jsonInput">json</param>
            /// <returns>去除key引号</returns>
            public string JsonRegex(string jsonInput)
            {
                string result=string.Empty;
                try
                {
                    string pattern = ""(\w+)"(\s*:\s*)";
                    string replacement = "$1$2";
                    System.Text.RegularExpressions.Regex rgx = new System.Text.RegularExpressions.Regex(pattern);
                    result = rgx.Replace(jsonInput, replacement);
                }
                catch (Exception ex)
                {
                    result = jsonInput;
                }
                return result;
            }

    测试案例:

    json:{"action_r": [{"spr": "1", "mas": "21", "mgt": "入职"}, {"spr": "1", "mas": "22", "mgt": "转岗"}]}

    public string PA_Test()
    {
        string str = "{"action_r": [{"spr": "1", "mas": "21", "mgt": "入职"}, {"spr": "1", "mas": "22", "mgt": "转岗"}]}";
        str = this.JsonRegex(str);
                
        return str;
    }

    返回结果:

    {action_r: [{spr: "1", mas: "21", mgt: "入职"}, {spr: "1", mas: "22", mgt: "转岗"}]}

    参考:

    http://bbs.csdn.net/topics/330267907

    http://www.cnblogs.com/cexm/p/6322011.html

    http://www.jb51.net/article/21529.htm

    http://blog.csdn.net/graceMeMe/article/details/37562327?locationNum=9

  • 相关阅读:
    PRCT-1302 the OCR has an invalid ip address
    函数listen
    函数bind
    函数socket
    lamp。查看版本
    yii 日期插件
    UCenter 的目录结构
    API接口
    返回标签数据示例 (PHP)
    应用接口函数
  • 原文地址:https://www.cnblogs.com/wangfuyou/p/7778271.html
Copyright © 2011-2022 走看看