首页 > 解决方案 > 如何使用 Newtonsoft.Json 从 Json 数组中获取对象列表

问题描述

我从服务返回了以下 JSON 字符串:

{
    "products": {
        "product_1": [
            "this is description for product 1"
        ],
        "product_2": [
            "this is description for product 2"
        ]
    }
}

我想做的是将它转换为 c# 中的产品类列表。我的产品类看起来像这样

public class Product
{
    public String Name{ get; set; }

    public String Description{ get; set; }
}

因此,例如上面的例子,“product_1”将被映射到 Name 属性,“this is description for product 1”需要映射到产品类的 Description 属性。基于 Json,我想返回一个列表。

谁能帮助我如何使用 Newtonsoft.Json 实现这一目标?

谢谢

标签: c#jsonjson.net

解决方案


推荐阅读