首页 > 解决方案 > 反序列化嵌套在数组中的对象

问题描述

我正在努力反序列化从 API 接收的以下 JSON 字符串:

{
  "appointment_types": [
    {
      "id": 279148,
      "max_attendees": 1,
      "name": "Follow up",
      "billable_item": {
        "links": {
          "self": "https://api.cliniko.com/v1/billable_items/485545"
        }
      },
      "practitioners": {
        "links": {
          "self": "https://api.cliniko.com/v1/appointment_types/279148/practitioners"
        }
      }
    },
    {
      "id": 279149,
      "max_attendees": 1,
      "name": "Assessment",
      "billable_item": {
        "links": {
          "self": "https://api.cliniko.com/v1/billable_items/490437"
        }
      },
      "practitioners": {
        "links": {
          "self": "https://api.cliniko.com/v1/appointment_types/279149/practitioners"
        }
      }
    }
  ],
  "total_entries": 17,
  "links": {
    "self": "https://api.cliniko.com/v1/appointment_types?page=1"
  }
}

我已经搜索过,但找不到任何适用于上述内容的内容。

任何可能使我走上正轨的指针将不胜感激。

标签: c#json.net

解决方案


这对我来说似乎工作得很好,只是使用动态......

dynamic d = JObject.Parse(json);
var totalNumber = d.total_entries.ToString();
var theId = d.appointment_types[0].id.ToString();

你试过什么?


推荐阅读