下面的代码没有按预期工作。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 循环不起作用。Go 编译器给出错误“无法范围覆盖问题 [1](类型接口 {})”
1 回答
慕田峪4524236
TA贡献1875条经验 获得超5个赞
让去理解questions[1]
有类型是map
for key, val := range questions[1].(map[interface{}]string) { fmt.Printf("%v : %v\n", key, val) }
- 1 回答
- 0 关注
- 93 浏览
添加回答
举报
0/150
提交
取消