using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace CoreAgent.Domain.Helpers { public static class JsonHelper { /// /// 对象序列化 /// /// 对象 /// 是否使用textjson /// 返回json字符串 public static string ObjToJson(this object obj, bool isUseTextJson = false) { if (isUseTextJson) { return System.Text.Json.JsonSerializer.Serialize(obj); } else { return Newtonsoft.Json.JsonConvert.SerializeObject(obj); } } /// /// json反序列化obj /// /// 反序列类型 /// json /// 是否使用textjson /// 返回对象 public static T JsonToObj(this string strJson, bool isUseTextJson = false) { if (isUseTextJson) { return System.Text.Json.JsonSerializer.Deserialize(strJson); } else { return Newtonsoft.Json.JsonConvert.DeserializeObject(strJson); } } } }