我有以下格式的json{ "status_code": 200, "status_message": "OK", "response": { "Messages": [ "CODE_NOT_AVAILABLE" ], "UnknownDevices": { "": [ "6", "7", "8", "9", "10" ] } }}正如我們看到的,我們缺少一個索引鍵,在 unknownDevices 之后,我試圖通過以下方式使用 golan 解組這個 jsonpackage mainimport ( "encoding/json" "fmt")type pushWooshResponse struct { Status int `json:"status_code"` Status_msg string `json:"status_message"` Response response}type response struct { Message []string `json:"Messages"` UnknownDevices devices}type devices struct { Udevices []string `json:""`}func main() { itemInfoR := `{"status_code":200,"status_message":"OK","response":{"Messages":["CODE_NOT_AVAILABLE"],"UnknownDevices":{"devices":["6","7","8","9","10"]}}}` itemInfoBytes := []byte(itemInfoR) var ItemInfo pushWooshResponse er := json.Unmarshal(itemInfoBytes, &ItemInfo) if er != nil { fmt.Println("Error", er.Error()) } else { fmt.Println(ItemInfo) }}輸出是{200 OK {[CODE_NOT_AVAILABLE] {[]}}}除了最后一部分外,一切都正常,我無法解開這一部分。你能幫我把 json 的最后一部分 umarhal 嗎?
在golang中解析沒有索引名稱的json
慕婉清6462132
2021-11-01 16:10:29