golang 多維map

wangchunbo發表於2021-03-12
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

來源:blog.csdn.net/nx_xn/article/detail...

本作品採用《CC 協議》,轉載必須註明作者和本文連結
感謝關注 上海PHP自學中心-免費程式設計視訊教學|

相關文章