我看了这个问题和答案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" : ""
}