可以使用以下代码初始化一个有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对象,可以使用new关键字创建一个空的List对象,然后再向其中添加ChoicesItem实例。在创建ChoicesItem实例时,需要为delta属性赋值一个Delta实例,同样也是使用new关键字创建一个Delta实例,然后为其content属性赋值。

c# 如何初始化一个有3层的实体json类 public class Delta summary summary public string content get; set; public class ChoicesItem summary

原文地址: https://www.cveoy.top/t/topic/baSS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录