c# 如何初始化一个有3层的实体json类 public class Delta summary summary public string content get; set; public class ChoicesItem summary
可以使用以下代码初始化一个有3层的实体json类:
gptrepose response = new gptrepose
{
id = "123",
@object = "test",
created = 123456,
model = "gpt",
choices = new List<ChoicesItem>
{
new ChoicesItem
{
delta = new Delta
{
content = "test1"
},
index = 1,
finish_reason = "complete"
},
new ChoicesItem
{
delta = new Delta
{
content = "test2"
},
index = 2,
finish_reason = "complete"
}
}
};
其中,通过new关键字创建了gptrepose、ChoicesItem和Delta类的实例,并为它们的属性赋值。在创建gptrepose实例时,需要为choices属性赋值一个List
原文地址: https://www.cveoy.top/t/topic/baSS 著作权归作者所有。请勿转载和采集!