Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 反序列化嵌套在数组中的对象_C#_Json.net - Fatal编程技术网

C# 反序列化嵌套在数组中的对象

C# 反序列化嵌套在数组中的对象,c#,json.net,C#,Json.net,我正在努力反序列化从API接收的以下JSON字符串: { "appointment_types": [ { "id": 279148, "max_attendees": 1, "name": "Follow up", "billable_item": { "links": { "self": "https://api.cliniko.com/v1/billable_items/485545"

我正在努力反序列化从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"
  }
}
我已经搜索过了,但是我找不到任何适合上述情况的东西


任何能让我走上正轨的建议都将不胜感激。

这似乎对我来说很好,只要使用dynamic

dynamic d = JObject.Parse(json);
var totalNumber = d.total_entries.ToString();
var theId = d.appointment_types[0].id.ToString();
你尝试过什么?

我会为结构创建c#类,然后用于反序列化。(它速度很快,而且已经是c#了,但您必须添加引用。)

这是我的密码:

class Program
{
    static void Main(string[] args)
    {
        string json = File.ReadAllText("demo.json"); //Your json here
        RequestResult requestResult = Newtonsoft.Json.JsonConvert.DeserializeObject<RequestResult>(json); //There is your result
        Console.WriteLine("Done!");
        Console.ReadLine();
    }
}

class RequestResult
{
    public AppointmentType[] appointment_types;
    public int total_entries;
    public Link links;
}

class Practitioners
{
    public Link links;
}

class BillableItem
{
    public Link links;
}

class Link
{
    public string self;
}

class AppointmentType
{
    public int id;
    public int max_attendees;
    public string name;
    public BillableItem billable_item;
    public Practitioners practitioners;
}
类程序
{
静态void Main(字符串[]参数)
{
string json=File.ReadAllText(“demo.json”);//这里是您的json
RequestResult RequestResult=Newtonsoft.Json.JsonConvert.DeserializeObject(Json);//这是您的结果
控制台。WriteLine(“完成!”);
Console.ReadLine();
}
}
类请求结果
{
公共任命类型[]任命类型;
公共int总输入;
公共链接;
}
班主任
{
公共链接;
}
类可计费项目
{
公共链接;
}
类链接
{
公共字符串自身;
}
班级任命类型
{
公共int id;
公众出席人数;
公共字符串名称;
公共收费项目收费项目;
公共执业人员;
}

然后将结果作为c#对象,intellisense和代码补全等功能都可以使用。

您使用的是哪种语言?如果是c#,您是否尝试过中提到的任何工具?这是一个好问题-如果这是javascript,例如,它没有序列化。抱歉,我正在使用C#,我已经使用json2csharp.com创建了一些类,但是经过几个小时的尝试和错误,我得到了绝对的成功nowhere@Ash展示一个非真实的世界working@Ash在这个例子中,上面的解析非常好!这正是我需要的。