deserialize list of objects using json.net

心已入冬 提交于 2020-01-02 01:37:48

问题


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


回答1:


The type parameter for DeserializeObject has 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).



来源:https://stackoverflow.com/questions/11220776/deserialize-list-of-objects-using-json-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!