C#,JSON,反序列化到DataTable中

时间:2018-12-14 05:24:15

标签: c# json serialization datatable

我的JSON为

{{
  "attributes": {
    "type": "User",
    "url": "/services/data/v44.0/sobjects/User/0052F000002bO32QAE"
  },
  "Name": "demo Site Guest User",
  "UserType": "Guest",
  "Profile": {
    "attributes": {
      "type": "Profile",
      "url": "/services/data/v44.0/sobjects/Profile/00e2F000000DuoFQAS"
    },
    "Id": "00e2F000000DuoFQAS",
    "Name": "demo Profile"
  }
}}

{{
  "attributes": {
    "type": "User",
    "url": "/services/data/v44.0/sobjects/User/00541000006I1JyAAK"
  },
  "Name": "Scheduler Site Guest User",
  "UserType": "Guest",
  "Profile": {
    "attributes": {
      "type": "Profile",
      "url": "/services/data/v44.0/sobjects/Profile/00e41000000GhKdAAK"
    },
    "Id": "00e41000000GhKdAAK",
    "Name": "Scheduler Profile"
  }
}}

在上述JSON中,我想获取父元素“名称”和“ UserType”以及子元素“ Id”和“名称”,并将其转换为数据表。这些父元素和子元素是匿名的,因此我无法为其创建类。

我到了这里

dynamic responseRecs = (responseDetails.records as IEnumerable<object>).Cast<object>().ToList();

这给了我响应,但不确定如何遍历动态内容并获取父项和子项(忽略类型和网址),以便构建数据表。

任何帮助将不胜感激。谢谢

0 个答案:

没有答案