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