using System.IO;
using System.Text.Json;
using System.Threading.Tasks;
namespace ColdMint.scripts.serialization;
public static class JsonSerialization
{
private static JsonSerializerOptions _options = new JsonSerializerOptions
{
//Case-insensitive attribute matching
//不区分大小写的属性匹配
PropertyNameCaseInsensitive = true
};
///
/// Read a Json file to type T
/// 读取一个Json文件到T类型
///
///
///
///
public static async Task ReadJsonFileToObj(string path)
{
await using var openStream = File.OpenRead(path);
return await JsonSerializer.DeserializeAsync(openStream, _options);
}
public static async Task ReadJsonFileToObj(Stream openStream)
{
return await JsonSerializer.DeserializeAsync(openStream, _options);
}
}