地图范围循环中的空接口

时间:2018-11-25 13:33:35

标签: go interface

以下代码无法正常工作。

package main

import "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 个答案:

答案 0 :(得分:2)

开始理解npm config set ca "" 的类型为questions[1]

map