C#实现用正则表达式替换JSON中大字段的内容

        /// <summary>
        /// 过长的数据在日志中不显示
        /// </summary>
        /// <param name="orilog">原请求</param>
        /// <param name="ignore">需要过滤的参数</param>
        private  string RemoveIgnoreLog(string orilog, params string[] ignore)
        {
            if (string.IsNullOrWhiteSpace(orilog) || ignore == null || ignore.Length < 1) { return orilog; }
            foreach (var item in ignore)
            {
                Regex pattern = new Regex(@"""" + item + @""":\s?""(.+?)""");
                orilog = pattern.Replace(orilog, @"""" + item + @""":""数据过长,不写入日志""");
            }
            return orilog;
        }

 

posted @ 2023-08-16 13:12  【君莫笑】  阅读(82)  评论(0编辑  收藏  举报