2 回答

TA貢獻1891條經(jīng)驗 獲得超3個贊
你可以這樣做:
// if you know it is a first el in []interface{}
el := arr[0]
// and than you type cast it to []int
if arr, ok := el.([]int); ok {
fmt.Println(arr[0])
}
// or if you want to do the same thing for all elements (searching...)
for _, el := range arr {
if el, ok := el.([]int); ok {
// use el as a []int here
process(el)
}
}

TA貢獻1898條經(jīng)驗 獲得超8個贊
索引[]interface{}應(yīng)該像interfaceSlice[0]
例子:
a := []interface{}{1, 2, 3, 4, 5}
d := []interface{}{a}
var b []int
e := d[0].([]interface{})
for i := range e {
b = append(b, e[i].(int))
}
fmt.Println(b)
- 2 回答
- 0 關(guān)注
- 257 瀏覽
添加回答
舉報