请教一关于**切片追加**的问题

jinyong · · 704 次点击
stackoverflow解决: ```go var mylist []interface{} = enc["actions"].([]interface{}) mylist = append(mylist, "good") enc["actions"] = mylist ```
#1
更多评论
haoyupei
大道至简,始终如一
非常感谢,非常不错的例子
#2
就是加一个断言 ```go if v, ok := enc["actions"]; ok { if nv, ok := v.([]interface{}); ok { nv = append(nv, "good") enc["actions"] = nv } } else { enc["actions"] = []interface{}{"good"} } ```
#3