最初我的 json 格式是
"code": 0,
"message": "success",
"students": [
{
"id": "257633000000070001",
"name": "hjeke",
"percentage": 36,
"type": "Good",
},
{
"id": "257633000000073001",
"name": "Second",
"percentage": 4,
"type": "bad",
}]
所以我使用下面的类使用 Newtonsoft.json 进行反序列化
[DataContract]
public class students
{
[DataMember(Name = "code")]
public int Code { get; set; }
[DataMember(Name = "message")]
public string Message { get; set; }
[DataMember(Name = "students")]
public StudentDetail StudentDetail { get; set; }
}
[DataContract]
public class StudentDetail
{
[DataMember(Name = "id")]
public string ID { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "percentage")]
public double PercentageForEdit { get; set; }
[DataMember(Name = "type")]
public string Type { get; set; }
}
但是现在我的json变成了,
"code": 0,
"message": "success",
"students": {
"details":{
"hjeke": {
"id": "257633000000070001",
"name": "hjeke",
"percentage": 36,
"type": "Good",
},
"Second": {
"id": "257633000000073001",
"name": "Second",
"percentage": 4,
"type": "bad",
}
}
}
我应该如何改变我的学生班级,以便,
StudentDetails = JsonConvert.DeserializeObject<Students>(data);