/// <summary>
/// 反序列化
/// </summary>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
public static List<T> JsonToList<T>(string filePath)
{
string jsonStr = File.ReadAllText(filePath);
//反序列化
var list = new List<T>(JsonConvert.DeserializeObject<List<T>>(jsonStr));
return list;
}
/// <summary>
/// 反序列化
/// </summary>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
public static T JsonTo<T>(string filePath)
{
string jsonStr = File.ReadAllText(filePath);
//反序列化
var value = JsonConvert.DeserializeObject<T>(jsonStr);
return value;
}
标签:jsonStr,文件,读取,filePath,C#,DeserializeObject,序列化,string
From: https://www.cnblogs.com/qiutian-hao/p/18201523