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; }