下面的代碼沒有按預(yù)期工作。package mainimport "fmt"func main() { questions := make(map[int]interface{}) questions[1] = map[interface{}]string{ "q1": "This is Question - 1?", "op1": "This is Option - 1", "op2": "This is Option - 2", true: "This is Option - 1", } // This give map[interface {}]string fmt.Printf("%T \n", questions[1]) // This not working for key, val := range questions[1] { printf("%v : %v", key, val) }}遍及地圖的 for 循環(huán)不起作用。Go 編譯器給出錯誤“無法范圍覆蓋問題 [1](類型接口 {})”
1 回答

慕田峪4524236
TA貢獻(xiàn)1875條經(jīng)驗 獲得超5個贊
讓去理解questions[1]
有類型是map
for key, val := range questions[1].(map[interface{}]string) { fmt.Printf("%v : %v\n", key, val) }
- 1 回答
- 0 關(guān)注
- 129 瀏覽
添加回答
舉報
0/150
提交
取消