using YLErp.Commons; namespace YLErp.Helpers { public static class JsonBeautify { /// /// 提供一个简单美化版的数组对象JSON序列化 /// public static string Serialize(IEnumerable array, bool ignoreNullValue = true, bool camelCase = false) where T : class { if (array is null) { throw new ArgumentNullException(nameof(array)); } var sb = StringBuilderPool.Acquire().Append('[').AppendLine(); var sbLastIndex = sb.Length; foreach (var item in array) { sb.Append(item == null ? "null" : JsonHelper.Serialize(item)); sbLastIndex = sb.Length; sb.Append(',').AppendLine(); } if (sb.Length > sbLastIndex) { sb.Remove(sbLastIndex, sb.Length - sbLastIndex).AppendLine(); } return sb.Append(']').Release(); } } }