使用json.net反序列化对象列表 [英] deserialize list of objects using json.net

查看:83
本文介绍了使用json.net反序列化对象列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这堂课

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; }
}

我像这样反序列化

retObject = JsonConvert.DeserializeObject(Of Category)(jsonResp)

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

but for a list of category returned, how do i convert to List<Category>? thanks

推荐答案

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

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).

这篇关于使用json.net反序列化对象列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆