V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
SummerWQM
V2EX  ›  问与答

Go 语言 求指教

  •  
  •   SummerWQM · Sep 30, 2018 · 2008 views
    This topic created in 2772 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
        1
    Julio  
       Sep 30, 2018
    string(config["dev"])
    Julio
        2
    Julio  
       Sep 30, 2018   ❤️ 1
    @Julio 是 config["dev"].(string)
    SummerWQM
        3
    SummerWQM  
    OP
       Sep 30, 2018
    @Julio Soga
    goofool
        4
    goofool  
       Sep 30, 2018
    if b, ok := config["dev"].(string); ok {
    fmt.Println(b)
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2408 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 06:05 · PVG 14:05 · LAX 23:05 · JFK 02:05
    ♥ Do have faith in what you're doing.