package main

import (
    "fmt"
)

type pl struct {
    method      interface{}
    clientToken interface{}
    Params      pa
}

type pa struct {
    PowerSwitch interface{}
    ip          interface{}
}

func main() {
    //第一种方法
    s := make(map[interface{}]interface{})
    s["a"] = "a"
    s["b"] = "b"
    s[1] = 1

    b := make(map[interface{}]interface{})
    b["a"] = "ba"
    b["e"] = 45
    b[1] = "str"
    b[2] = 2
    b["我是map"] = s
    fmt.Println(b)
    fmt.Println(b["s"].(map[interface{}]interface{})[1])

    //第二种方法
    c := make(map[interface{}]interface{})
    c["c"] = "c"
    c[3] = 3
    c["e"] = make(map[interface{}]interface{})
    c["e"].(map[interface{}]interface{})["k"] = "ke"
    fmt.Println(c)
    fmt.Println(c["e"].(map[interface{}]interface{})["k"])

    //第三种方法
    d := make(map[interface{}]interface{})
    d["m"] = "m"
    d["e"] = map[interface{}]interface{}{"j": "je"}
    fmt.Println(d)
    fmt.Println(d["e"].(map[interface{}]interface{})["j"])

    //第四种方法
    st := pl{method: "report", clientToken: "1243424"}
    st.Params = pa{0, "2.2.1.1"}
    fmt.Println(st)
    fmt.Println(st.Params.ip)
}

运行结果:

golang 多维map

本作品采用《CC 协议》,转载必须注明作者和本文链接
感谢关注 上海PHP自学中心-免费编程视频教学|