且构网

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

将嵌套的JSON反序列化为C#对象

更新时间:2023-02-17 19:24:55

对于"Items",请使用Dictionary<string, List<Info>>,即:

class Response
{
    public Dictionary<string, List<Info>> Items { get; set; }
    public string[] Errors { get; set; }
}

class Info
{
    public string Prop1 { get; set; }
    public string Prop2 { get; set; }
    public int Prop3 { get; set; }
    public bool Prop4 { get; set; }
}

这假定项名称"Item322A""Item2B"会因响应而异,并以字典键的形式读取这些名称.

This assumes that the item names "Item322A" and "Item2B" will vary from response to response, and reads these names in as the dictionary keys.

示例小提琴.