原文:https://www.az1314.cn/art/69
------------------------------------------
mapA := make([string]
interface
{})
mapB := make([string]
interface
{})
mapA[
"name"
] =
"小文"
mapA[
"age"
] = 25
mapB[
"mapA"
] = mapA
for
k, v := range mapB {
(k == ) {
for
_, v1 := range v{
fmt.Println(v1)
}
}
}
//cannot range over v (type interface {}) 不能对一个空接口进行range
//所以再来看看下 上面发生了什么
//mapA["name"] = "xiaowen" //字符串被强转成interface{}
//mapA["ege"] = 25 //int被强转成interface{}
//mapB["mapA"] = mapA //mapA被转成interface{}了 取出可以强转成 map[string]interface{}
for
k, v := range mapB {
if
(k ==
"mapA"
) {
for
_, v1 := range v.(map[string]
interface
{}){
fmt.Println(v1)
}
}
}
//这里把v再转成mapA的类型即可
//强类型语言要时刻记着类型的转换奥!
原文地址:https://www.cnblogs.com/oxspirt/p/10977633.html