Dictionary 如何从使用接口{}键入的golang map[string]字符串中提取值
我有这样的想法:Dictionary 如何从使用接口{}键入的golang map[string]字符串中提取值,dictionary,go,types,Dictionary,Go,Types,我有这样的想法: x1 := someFunctionWithAnInterfaceReturnValue() 基本类型如下所示: x2 := map[string] string{"hello": "world"} 如何访问x1中的值 基本上,我想要x1的等效值: var value string = x2["hello"] 使用: x1 := someFunctionWithAnInterfaceReturnValue() x2, ok := x1.(map[string]strin
x1 := someFunctionWithAnInterfaceReturnValue()
基本类型如下所示:
x2 := map[string] string{"hello": "world"}
如何访问x1中的值
基本上,我想要x1的等效值:
var value string = x2["hello"]
使用:
x1 := someFunctionWithAnInterfaceReturnValue()
x2, ok := x1.(map[string]string)
if !ok {
// handle unexpected type
}
var value string = x2["hello"]