c# - 如何使用 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 实现这一目标?
谢谢
解决方案
推荐阅读
- android - 调用 clearSpans 时的 EditText 块
- javascript - 使用循环中的变量更改类名
- linux - 为什么安装的 Centos 系统使用 ld.2.17,但编译相同版本的 glibc-2.17 会产生 ld.so
- python - 编写此代码的更好方法是什么?
- python - datetime 在 python 中以 timedelta 或 datetime 格式返回时间值
- android - 如何在android中以编程方式裁剪特定尺寸的图像
- xquery - 有没有办法在 for 循环中查找重复值而不返回重复值的 2 倍?
- r - 使用 dplyr 编程时 ensym 和 enquo 有什么区别?
- arduino - Arduino超声波传感器值不为0,如果超声波传感器前面有物体,则无法更改值
- sql - 预定义值的 SQL 结果表