慕妹3146593
按照另一个答案中的建议定义结构后:type MyStruct struct { MyField int}type Result struct { Name string Objects []MyStruct}然后你可以Result像这样初始化一个对象:result := Result{ Name: "I am Groot", Objects: []MyStruct{ { MyField: 1, }, { MyField: 2, }, { MyField: 3, }, },}完整代码:package mainimport "fmt"func main() { result := Result{ Name: "I am Groot", Objects: []MyStruct{ { MyField: 1, }, { MyField: 2, }, { MyField: 3, }, }, } fmt.Println(result)}type MyStruct struct { MyField int}type Result struct { Name string Objects []MyStruct}你可以在这个Go Playground 中验证这一点。