【发布时间】:2020-06-05 08:03:20
【问题描述】:
给出困难的部分
const string _studentRepositoryPath = @"students.json";
static void Save() {
using (var file = File.CreateText(_studentRepositoryPath))
{
file.WriteAsync(JsonSerializer.Serialize(studentsList));
}
}
static List<Student> Read() {
return JsonSerializer.Deserialize<List<Student>>(File.ReadAllText(_studentRepositoryPath));
}
static List<Student> studentsList = new List<Student>();
尝试将要保存的数据保存到 JSON 文件中,以便在重新打开程序时可以搜索学生。
问题:创建学生对象后 JSON 文件更新,但退出并重新打开程序时显示学生不存在。
【问题讨论】: