【发布时间】:2016-04-15 12:04:45
【问题描述】:
我有以下课程:
public class Student
{
public int studentNumber;
public string testWeek;
public string topics;
}
我对其做了一些处理,将其序列化并保存在一个文件中。它看起来像这样:
[
{
"studentNumber": 1,
"testWeek": "1",
"topics": "5 & 8"
},
{
"studentNumber": 2,
"testWeek": "1",
"topics": "5 & 8"
},
{
"studentNumber": 3,
"testWeek": "1",
"topics": "5 & 8"
},
{
"studentNumber": 4,
"testWeek": "1",
"topics": "5 & 8"
},
{
"studentNumber": 5,
"testWeek": "1",
"topics": "5 & 8"
}
]
稍后我想反序列化它,以便我可以再次处理它。我有这个代码
Student[] arr = new Student[numberOfStudentsInClass];
arr = JsonConvert.DeserializeObject<Student>(File.ReadAllText(_selectedClass))
其中 _selectedClass 是包含文件名的字符串。但我收到一个错误
无法将 WindowsFormApplicationsForm1.Form.Student 转换为 WindowsFormApplicationsForm1.Form.Student[]
【问题讨论】: