go json解析问题 大牛们帮帮忙

YGoldking · · 987 次点击
是想要这个么? package main import ( "encoding/json" "fmt" ) type Test struct { Code int `json:"code"` Data struct { Song struct { Count int `json:"count"` ItemList []struct { Albummid string `json:"albummid"` Docid string `json:"docid"` Id string `json:"id"` Mid string `json:"mid"` Name string `json:"name"` Singer string `json:"singer"` } } `json:"song"` Name string `json:"name"` Order int `json:"order"` Type int `json:"type"` } `json:"data"` Subcode int `json:"subcode"` } func main() { test := ` { "code": 0, "data": { "song": { "count": 2, "itemlist": [{ "albummid": "001ZaCQY2OxVMg", "docid": "4960718353595419009", "id": "108041208", "mid": "000lH7Do3X6Aot", "name": "雪阳", "singer": "鹿予" }, { "albummid": "001ZaCQY2OxVMg", "docid": "4277524965976373789", "id": "107195477", "mid": "0004snbm3ZMeFz", "name": "雪阳花", "singer": "林爽" }], "name": "单曲", "order": 0, "type": 1 } }, "subcode": 0 }` var t Test err := json.Unmarshal([]byte(test), &t) if err != nil { fmt.Println(err) } fmt.Println(t.Data.Song.ItemList[1].Albummid) fmt.Println(t.Data.Song.ItemList) }
#7
更多评论
460821714
Don't go looking for Mr.Right,go looking for Mr.Right now.
看看你结构体怎么定义的
#1
你这全是小写的,首字母请大写,golang是支持嵌套的
#2