您的变量是a
map[string]interface {},表示键是字符串,但值可以是任何值。通常,访问此方法的方式是:mvVar := myMap[key].(VariableType)
或在字符串值的情况下:
id := res["strID"].(string)
请注意,如果类型不正确或映射中不存在键,这将引起恐慌,但是我建议您阅读更多有关Go映射和类型断言的信息。
在此处阅读有关地图的信息:http :
//golang.org/doc/effective_go.html#maps
有关类型声明和接口转换的信息,请参见:http
:
//golang.org/doc/effective_go.html#interface_conversions
避免出现恐慌的安全方法是这样的:
var id stringvar ok boolif x, found := res["strID"]; found { if id, ok = x.(string); !ok { //do whatever you want to handle errors - this means this wasn't a string }} else { //handle error - the map didn't contain this key}


