我有一些 JSON,例如:
{
"companyName": "Software Inc.",
"employees": [
{
"employeeName": "Sally"
},
{
"employeeName": "Jimmy"
}
]
}
我想将其反序列化为:
public class Company
{
public string companyName { get; set; }
public IList<Employee> employees { get; set; }
}
public class Employee
{
public string employeeName { get; set; }
public Company employer { get; set; }
}
如何让 JSON.NET 设置“雇主”参考?我尝试使用 a CustomCreationConverter
,但该public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
方法不包含对当前父对象的任何引用。