i have the following json string (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方法可能实现吗?还是我需要手动反序列化?
item.References [0] .Type == null
以此类推...您没有遇到这种情况吗? - lboregardList<T>
值是空的。正在调查... - Jon Skeet