30 lines
930 B
C#
30 lines
930 B
C#
using System.Text.Json;
|
|
|
|
namespace FAuth.Extensions
|
|
{
|
|
/// <summary>
|
|
/// 微软提供的Json序列化器封装
|
|
/// </summary>
|
|
public class MsJsonProvider:IJsonProvider
|
|
{
|
|
/// <summary>
|
|
/// 从对象序列化字符串
|
|
/// </summary>
|
|
/// <typeparam name="T">对象类型</typeparam>
|
|
/// <param name="obj">要序列化的对象</param>
|
|
/// <returns>字符串</returns>
|
|
public string GetJson<T>(T obj) {
|
|
return JsonSerializer.Serialize<T>(obj);
|
|
}
|
|
/// <summary>
|
|
/// 从字符串反序列化对象
|
|
/// </summary>
|
|
/// <typeparam name="T">对象的类型</typeparam>
|
|
/// <param name="json">json字符串</param>
|
|
/// <returns>对象实例</returns>
|
|
public T GetObj<T>(string json) {
|
|
return JsonSerializer.Deserialize<T>(json);
|
|
}
|
|
}
|
|
}
|