猿问

将字符串、整数和数组的 JSON 对象解组为映射

我喜欢使用 Decode() 解组 JSON 字符串:


var message Message

decoder := json.NewDecoder(s)

err = decoder.Decode(&message)

我的数据结构是


type Message map[string]interface{}

测试数据如下:


{

  "names": [

    "HINDERNIS",

    "TROCKNET",

    "UMGEBENDEN"

  ], 

  "id":1189,

  "command":"checkNames"

}

它适用于数字和字符串,但对于字符串数组,我得到以下恐慌:


panic: interface conversion: interface is []interface {}, not []string


慕容708150
浏览 163回答 1
1回答
随时随地看视频慕课网APP

相关分类

Go
我要回答