我有以下 json 字符串(jsonString)
[
{
"name":"Fruits",
"references":[
{"stream":{"type":"reference","size":"original",id":"1"}},
],
"arts":[
{"stream":{"type":"art","size":"original","id":"4"}},
{"stream":{"type":"art","size":"medium","id":"9"}},
]
}
]
和以下 C# 对象
class Item
{
public string Name { get; set; }
public List<Stream> References { get; set; }
public List<Stream> Arts { get; set; }
public Item()
{
}
}
class Stream
{
public string Type { get; set; }
public string Size { get; set; }
public string Id { get; set; }
public Stream()
{
}
}
和下面的代码
Item item = JsonConvert.DeserializeObject<Item>(jsonString);
当我运行代码时,它创建了正确数量的引用和艺术,但每个流都有空值(类型 = null,大小 = null)。
是否可以执行此 json.net deserializeobject 方法,还是应该手动反序列化?