using System; using System.ComponentModel; using System.Linq; using System.Text; using System.Text.Encodings.Web; using System.Text.Json; using System.Text.Json.Serialization; using System.Text.Unicode; public static class ObjectExtension { public static string ToJsonStr(this object obj) { return Newtonsoft.Json.JsonConvert.SerializeObject(obj); } public static T JsonStrToObj(this string obj) { return Newtonsoft.Json.JsonConvert.DeserializeObject(obj); } /// /// 将源对象通过Json序列化为一个新对象 /// /// 返回对象泛型类型 /// 源对象 /// public static T To(this object obj) { var str = obj.ToJsonStr(); var objNew = str.JsonStrToObj(); return objNew; } }