使用 json.net 反序列化对象列表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11220776/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
deserialize list of objects using json.net
提问by Smith
i have this class
我有这门课
public class Image
{
public string url { get; set; }
public string url_40px { get; set; }
public string url_50px { get; set; }
}
public class Category
{
public List<int> ancestor_ids { get; set; }
public int parent_id { get; set; }
public List<object> children_ids { get; set; }
public string nodename { get; set; }
public int num_parts { get; set; }
public List<Image> images { get; set; }
public string __class__ { get; set; }
public int id { get; set; }
}
and i deserialize it like this
我像这样反序列化它
retObject = JsonConvert.DeserializeObject(Of Category)(jsonResp)
but for a list of category returned, how do i convert to List<Category>?
thanks
但是对于返回的类别列表,我如何转换为List<Category>?谢谢
回答by fero
The type parameter for DeserializeObjecthas to be List<Category>instead of Category. I don't know how to write in VB, but in C#, it would be JsonConvert.DeserializeObject<List<Category>>(json).
的类型参数DeserializeObject必须是List<Category>而不是Category。我不知道如何在 VB 中编写,但在 C# 中,它将是JsonConvert.DeserializeObject<List<Category>>(json).

