using System.Collections.Generic; using System.Linq; using Furion.JsonSerialization; using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace GDZZ.Core; /// /// Json序列化工具类 /// public static class JsonUtil { /// /// JSON 字符串转 Object /// /// /// /// public static T ToObject(this string json) { json = json.Replace(" ", ""); return json == null ? default(T) : JsonConvert.DeserializeObject(json); } /// /// JSON 字符串转 Object /// /// /// public static object ToObject(this string Json) { return string.IsNullOrEmpty(Json) ? null : JsonConvert.DeserializeObject(Json); } /// /// Object 转 JSON字符串 /// /// /// public static string ToJsonString(this object obj) { return obj == null ? string.Empty : JsonConvert.SerializeObject(obj); } /// /// JSON 字符串转 JObject /// /// /// public static JObject ToJObject(this string json) { return json == null ? JObject.Parse("{}") : JObject.Parse(json.Replace(" ", "")); } /// /// Dictionary 字符串转 Object /// /// /// /// public static T ToObject(this IDictionary dictionary) { return dictionary.ToJsonString().ToObject(); } /// /// 把数组转为逗号连接的字符串 /// /// /// /// public static string ArrayToString(dynamic data, string Str) { string resStr = Str; foreach (var item in data) { if (resStr != "") { resStr += ","; } if (item is string) { resStr += item; } else { resStr += item.ToString(); } } return resStr; } /// /// 判断是否有交集 /// /// /// /// /// public static bool IsArrayIntersection(List list1, List list2) { List t = list1.Distinct().ToList(); var exceptArr = t.Except(list2).ToList(); if (exceptArr.Count < t.Count) { return true; } else { return false; } } }