1
我喜欢解组使用解码()JSON字符串:解组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
我选择第二。我将map [string] interface {}类型更改为struct {Id int Command String Names [] string},然后像以前一样使用Decode()。工作正常。 – Michael