如何聲明結(jié)構(gòu)體字面量數(shù)組?去:type Ping struct { Content []aContent}type aContent struct { Type string Id string Created_at int64}func main() { f := Ping{Content: []aContent{Type: "Hello", Id: "asdf"}} fmt.Println(f)}代碼可以在這里找到:http : //play.golang.org/p/-SyRw6dDUm
1 回答

江戶川亂折騰
TA貢獻1851條經(jīng)驗 獲得超5個贊
你只需要另一對括號。
[]aContent{{Type: "Hello", Id: "asdf"}, {Type: "World", Id: "ghij"}}}
^ ^
here and here
這是數(shù)組的一對,數(shù)組中的每個結(jié)構(gòu)一個。
- 1 回答
- 0 關注
- 216 瀏覽
添加回答
舉報
0/150
提交
取消