我试图使用Json.Net库对这个Json进行反序列化:
{
"Employees": [
{
"Employee": {
"Name": "AAA",
"Info": [
{
"Signature": "aaa"
},
{
"Group": "AaA"
},
{
"E-mail": "aAa"
},
{
"Tfn home": "1234"
},
{
"Tfn mobile": "1324"
},
{
"Tfn work": "1234"
},
{
"Tfn pager": "1234"
}
]
}
},
{
"Employee": {
"Name": "BBB",
"Info": [
{
"Signature": "bbb"
},
{
"Group": "BbB"
},
{
"E-mail": "bBb"
},
{
"Tfn home": "1234"
},
{
"Tfn mobile": "1234"
},
{
"Tfn work": "1234"
},
{
"Tfn pager": "1234"
}
]
}
}
]
}
Into the following:-
public class Foo
{
private ObservableCollection<Employee> _fooEmployees = new ObservableCollection<Employee>();
public ObservableCollection<Employee> FooEmployees
{
get { return _fooEmployees; }
set { _fooEmployees = value; }
}
}
[JsonObject]
public class Employee
{
[JsonProperty(PropertyName = "Name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "Info")]
private ObservableCollection<Infomation> _infoList = new ObservableCollection<Infomation>();
public ObservableCollection<Infomation> InfoList
{
get { return _infoList; }
set
{
_infoList = value;
}
}
}
[JsonDictionary]
public abstract class Infomation
{
[JsonProperty(PropertyName = "Signature")]
public string Signature { get; set; }
[JsonProperty(PropertyName = "Group")]
public string Group { get; set; }
[JsonProperty(PropertyName = "E-mail")]
public string Email { get; set; }
[JsonProperty(PropertyName = "Tfn home")]
public string TfnHome { get; set; }
[JsonProperty(PropertyName = "Tfn mobile")]
public string TfnMobile { get; set; }
[JsonProperty(PropertyName = "Tfn work")]
public string TfnWork { get; set; }
[JsonProperty(PropertyName = "Tfn pager")]
public string TfnPager { get; set; }
}
使用以下代码行:-
var kol = JsonConvert.DeserializeObject<Foo>(json);
问题在于Kol返回的FooEmployees数量为0。
请问有人能指导我为什么它不起作用吗?