我查看了这个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" : ""
}
答案 0 :(得分:4)
您需要一个集合,但是您传递了一个要序列化的对象。
@Override
public void run(ApplicationArguments args) throws Exception {
bookRepo.save(Book.builder().build());
}