可以在 Go 中获取 JSON 的值
我是 Go 的新手。我正在尝试读取一个 JSON 文件并获取其中的一部分,然后使用获得的值进行操作。我的 JSON 在文件 example.json 中:{"results":[{"statement_id":0,"series":[{"name":"cpu/node_utilization","columns":["time","distinct"],"values":[[10,1],[11,3],[13,5]]}]}]}所以我想得到的是获取所有元素总和的“值”。在这种情况下:1+3+5这是我的代码。我可以得到结果,但后来我没能得到系列。这是我的代码:package mainimport ( "encoding/json" "fmt" "io/ioutil" "os")func main() { // Open our jsonFile jsonFile, err := os.Open("example.json") // if we os.Open returns an error then handle it if err != nil { fmt.Println(err) } fmt.Println("Successfully Opened example.json") // defer the closing of our jsonFile so that we can parse it later on defer jsonFile.Close() byteValue, _ := ioutil.ReadAll(jsonFile) var all_data map[string]interface{} json.Unmarshal([]byte(byteValue), &all_data) fmt.Println(all_data["results"])}我尝试过不同的解决方案,例如 all_data["results"].(map[string]interface{})["series"]) 但问题是地图在数组中,我不知道如何解决。