/// <summary> /// Json序列化帮助类 /// </summary> public class JsonSerializerHelper { /// <summary> /// 将对象序列化为Json字符串(此Json序列化,是“不安全的放松JSON转义”,即不会将物特殊符号和中文进行转码) /// </summary> /// <param name="obj"></param> /// <returns></returns> public static string Serialize<T>(T obj) { JsonSerializerOptions jsonOptions = new JsonSerializerOptions { Encoder = JavaScriptEncoder.UnsafeRelaxedJsonEscaping }; return System.Text.Json.JsonSerializer.Serialize(obj, jsonOptions); } /// <summary> /// 将Json字符串反序列化为对象 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="json"></param> /// <returns></returns> public static T? Deserialize<T>(string json) { return System.Text.Json.JsonSerializer.Deserialize<T>(json); } }
标签:转码,JSON,Json,序列化,特殊符号,public From: https://www.cnblogs.com/friend/p/18675149