最初、私の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);