我喜欢使用 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
相关分类