【发布时间】:2018-10-18 08:45:45
【问题描述】:
我查看了这个Create tree hierarchy in JSON with LINQ 问题和答案,它与我所需要的很接近。但是我无法生成嵌套数组,如下所示,因为我使用的是 json.net
Class.cs
public class RootObject
{
public List<Attribute> test { get; set; }
}
public class Attribute
{
public string testKey { get; set; }
public string start { get; set; }
public string finish { get; set; }
public string comment { get; set; }
public string status { get; set; }
}
public class AttributeData
{
public Attribute AttributeDataOps()
{
***Attribute DATA***
}
}
Program.cs
Attribute attribute = new Attribute();
AttributeData attributeData = new AttributeData();
string JSONresult = JsonConvert.SerializeObject(attribute);
string path = @"C:\file.json";
预期结果
{
"tests" : [
{
"testKey" : "",
"start" : "",
"finish" : "",
"comment" : "",
"status" : ""
}
]
}
当前结果
{
"testKey" : "",
"start" : "",
"finish" : "",
"comment" : "",
"status" : ""
}
【问题讨论】: