Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.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_C#_Json - Fatal编程技术网

C# c中带有数组和对象的Json

C# c中带有数组和对象的Json,c#,json,C#,Json,我是Json格式的新手,我正在尝试编写一个使用Json格式的c程序,如何用c编写这个Json { "request": [ { "md5": "8dfa1440953c3d93daafeae4a5daa326", "features": [ "te", "av", "extraction" ],

我是Json格式的新手,我正在尝试编写一个使用Json格式的c程序,如何用c编写这个Json

{    
 "request": [         
  {            
   "md5": "8dfa1440953c3d93daafeae4a5daa326",         
    "features": [          
    "te",              
    "av", 
    "extraction"       
    ],    
     "file_name": "example.xls"   
      "te": {             
           "reports": [              
           "xml",               
           "pdf"              
           ]           
         }             
        "extraction": {            
          "method": "pdf"          
           }        
         }  
      ] 
   }
以下是我的尝试: 以下是输出: 试试这个

输出

{
  "request": [
    {
      "md5": "8dfa1440953c3d93daafeae4a5daa326",
      "features": [
        "te",
        "av",
        "extraction"
      ],
      "file_name": "example.xls",
      "te": {
        "reports": [
          "xml",
          "pdf"
        ]
      },
      "extraction": {
        "method": "pdf"
      }
    }
  ]
}
代码

static void Main(string[] args)
{
    var req = new myRequest
    {
        request = new[] {
        new myJson
                    {
                        md5 = "8dfa1440953c3d93daafeae4a5daa326",
                        file_name = "example.xls",
                        features = new[] { "te", "av", "extraction" },
                        te = new te { reports = new[] { "xml", "pdf" } },
                        extraction = new ext { method = "pdf" }
                    }
        }
    };

    string json = JsonConvert.SerializeObject(req, Newtonsoft.Json.Formatting.Indented);
    Console.WriteLine(json);
}

public class myJson
{
    public string md5 { get; set; }
    public string[] features { get; set; }
    public string file_name { get; set; }
    public te te { get; set; }
    public ext extraction { get; set; }
}

public class myRequest
{
    public myJson[] request { get; set; }
}

public class te
{
    public string[] reports { get; set; }
}

public class ext
{
    public string method { get; set; }
}

请参阅request:[在Json的第二行,我如何添加此内容?@user9250580已更新。仍然不起作用,请您再次检查好吗?@user9250580对我来说很好,输出与您给出的示例输出完全相同。非常感谢!!
static void Main(string[] args)
{
    var req = new myRequest
    {
        request = new[] {
        new myJson
                    {
                        md5 = "8dfa1440953c3d93daafeae4a5daa326",
                        file_name = "example.xls",
                        features = new[] { "te", "av", "extraction" },
                        te = new te { reports = new[] { "xml", "pdf" } },
                        extraction = new ext { method = "pdf" }
                    }
        }
    };

    string json = JsonConvert.SerializeObject(req, Newtonsoft.Json.Formatting.Indented);
    Console.WriteLine(json);
}

public class myJson
{
    public string md5 { get; set; }
    public string[] features { get; set; }
    public string file_name { get; set; }
    public te te { get; set; }
    public ext extraction { get; set; }
}

public class myRequest
{
    public myJson[] request { get; set; }
}

public class te
{
    public string[] reports { get; set; }
}

public class ext
{
    public string method { get; set; }
}