SummerWQM
V2EX  ›  问与答

Go 语言 求指教

  •  
  •   SummerWQM · Sep 30, 2018 · 2338 views
    This topic created in 2958 days ago, the information mentioned may be changed or developed.

    config map[string]interface{}

    然后我 config 里面有一个值是 ["dev":"abc"]

    如何把 dev 赋值给一个 string 类型的 b eg:

    var b string

    这里怎么把 这个 interface 类型的值 赋值给这个 b 字符串类型

    4 replies  •  2018-09-30 17:43:13 +08:00
    Julio
    Julio
    Sep 30, 2018
    1
    string(config["dev"])
    Julio
    Julio
    Sep 30, 2018❤️1
    2
    @Julio 是 config["dev"].(string)
    SummerWQM
    SummerWQM
    OP
    Sep 30, 2018
    3
    @Julio Soga
    goofool
    goofool
    Sep 30, 2018
    4
    if b, ok := config["dev"].(string); ok {
    fmt.Println(b)
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5131 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 06:16 · PVG 14:16 · LAX 22:16 · JFK 01:16
    ♥ Do have faith in what you're doing.