我正在尝试在Go语言中获取接口映射的值。
val := reflect.ValueOf(Schema)
fmt.Println("VALUE = ", val)
fmt.Println("KIND = ", val.Kind())
if val.Kind() == reflect.Map {
fmt.Println("len = ", val.Len())
for key, element := range val.MapKeys() {
fmt.Println(key, element) // how to get the value?
}
}
这会输出:
VALUE = map[testString:foobar testInt:1 testBoolean:true testNumber:1 testDateTime:2017-10-06 08:15:30 +0100 +0100]
KIND = map
len = 5
0 testString
1 testInt
2 testBoolean
3 testNumber
4 testDateTime
我的问题:
如何获取map项的类型和值?