我有一个JSON响应如下
{
"Robert": [
{
"id": "123",
"class": "7th",
"lastname": "johnson"
}
],
"William": [
{
"id": "124",
"class": "7th",
"lastname": "parker"
}
]
}
我想将其映射到C#类。 使用在线转换器我得到以下结构
public class Robert {
public string id { get; set; }
public string class { get; set; }
public string lastname { get; set; }
}
public class William {
public string id { get; set; }
public string class { get; set; }
public string lastname { get; set; }
}
public class Application {
public IList<Robert> Robert { get; set; }
public IList<William> William { get; set; }
}
取而代之的是,我想将学生姓名映射为类属性之一。
public class Student{
public string Name{ get; set; } //Robert is mapped to this
public string id { get; set; }
public string class { get; set; }
public string lastname { get; set; }
}
我怎样才能做到这一点 ?