我主要看着在golang中取消編組下面的JSON數組。嵌套的Json數組構造golang中的un-marshalling
{
"status":{"code":"SUCCESS"},
"result": {
"total_records":1,
"records": [{
"last_modified_timestamp":1501209015807,
"dns_servers":null,
"is_secured":false,
"nis_domains":null,
"storage_platform_resource_key":"e1ee32f9-6576-11e7-82a8-00a098697714",
"name":"vs1",
"nis_servers":null,
"created_timestamp":1501208944094,
"dns_domains":null,
"key":"f59dacca-7379-11e7-82a8-00a098697714"
}]
}
}
我正在尋找這裏提取「關鍵」字段。試過下面的語法,但不能成功地得到我想要的。
var dat map[string]interface{}
// Unmarshall the JSON body
if err := json.Unmarshal(body, &dat); err != nil {
fmt.Println(err)
}
svmRecordsMap := dat["result"].(map[string]interface{})["records"]
fmt.Printf("%+v", svmRecordsMap)
result := (svmRecordsMap["key"].([]interface{})[0]).(map[string]interface{})
在這裏的任何幫助將非常感激。請注意,我沒有看到定義相應的結構並進行復制。
謝謝!
你能在「不能夠擴展到順利拿到了我想」?你有什麼具體問題? – Adrian
看看這個問題/答案:https://stackoverflow.com/questions/20154606/marshall-and-unmarshall-json-content-in-golang?rq=1 –
[Marshall and UnMarshall JSON Content in GoLang](https://stackoverflow.com/questions/20154606/marshall-and-unmarshall-json-content-in-golang) –