douwei9759 2019-09-05 08:52
浏览 1717

Golang将简单的代码数组转换为字符串

How to convert simple code array to string

a := []int{1,2,3}
ayam := "bebek" + a
fmt.Print(ayam)

example

[1,2,3]  => "[1,2,3]"

a (mismatched types string and []int)

  • 写回答

1条回答 默认 最新

  • duan0531 2019-09-06 19:05
    关注

    Your best bet would be to use json.Marshal().

    a := []int{1,2,3}
    s, _ := json.Marshal(a)
    // s should be "[1, 2, 3]"
    
    评论

报告相同问题?