且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用嵌套选择将JSON反序列化为POCO类

更新时间:2023-01-17 08:36:09

就像所有其他方法一样,为其构建一个类,并将其反序列化为该类:

Just like all of the others, build a class for it and it will be deserialized into it:

public class TagAudience
{
    public string id { get; set; }
    public string name { get; set; }
}

,然后使用List<TagAudience>代替Tags类中的List<object>.最后,当您想要了解这些内容时:

and then instead of List<object> in the Tags class, use List<TagAudience>. Finally, when you want to get to those:

audience = i.Tags.audience
    .Select(ta => new Audience
    {
        id = ta.id,
        name = ta.name
    }).FirstOrDefault()