使用json.net反序列化对象列表

Smi*_*ith 9 .net json json.net deserialization

我有这堂课

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; }
}
Run Code Online (Sandbox Code Playgroud)

我像这样反序列化它

retObject = JsonConvert.DeserializeObject(Of Category)(jsonResp)
Run Code Online (Sandbox Code Playgroud)

但是对于返回的类别列表,我该如何转换为List<Category>?谢谢

fer*_*ero 23

DeserializeObject必须List<Category>代替的类型参数Category.我不知道如何在VB中编写,但在C#中,它会是JsonConvert.DeserializeObject<List<Category>>(json).

  • 这个的VB将是JsonConvert.DeserializeObject(Of List(Of Category))(json) (2认同)