namespace Admin.NET.Core;
///
/// Newtonsoft.Json 实现
///
public class JsonSerializerProvider : IJsonSerializerProvider, ISingleton
{
///
/// 序列化对象
///
///
///
///
public string Serialize(object value, object jsonSerializerOptions = null)
{
return JsonConvert.SerializeObject(value, (jsonSerializerOptions ?? GetSerializerOptions()) as JsonSerializerSettings);
}
///
/// 反序列化字符串
///
///
///
///
///
public T Deserialize(string json, object jsonSerializerOptions = null)
{
return JsonConvert.DeserializeObject(json, (jsonSerializerOptions ?? GetSerializerOptions()) as JsonSerializerSettings);
}
///
/// 反序列化字符串
///
///
///
///
///
public object Deserialize(string json, Type returnType, object jsonSerializerOptions = null)
{
return JsonConvert.DeserializeObject(json, returnType, (jsonSerializerOptions ?? GetSerializerOptions()) as JsonSerializerSettings);
}
///
/// 返回读取全局配置的 JSON 选项
///
///
public object GetSerializerOptions()
{
return App.GetOptions()?.SerializerSettings;
}
}