m := map[string]int{"foo": 1, "bar": 3}
v := reflect.ValueOf(m)
i := v.Interface()
a := i.(map[string]int)
println(a["foo"])
Convert Value type to Map in Golang
最新推荐文章于 2024-07-16 09:25:14 发布
本文通过一个具体的Go语言代码示例介绍了如何使用反射来获取并操作map类型的变量。示例展示了将map[string]int类型的数据转换为反射值,再从反射值中提取原始数据的过程。
1万+

被折叠的 条评论
为什么被折叠?



