```go
package main
import (
"encoding/json"
"fmt"
"strconv"
)
type Person struct {
Age string `json:"status"`
Data Data `json:"data"`
Name string `json:"name"`
}
type Data struct {
Values []map[string]interface{} `json:"result"`
}
func main() {
// 假数据
b := []byte(`{"status":"success","wmd":{"result":"wmd"},"name":"wmd","data":{"resultType":"matrix","result":[{"metric":{"__name__":"namedprocess_namegroup_memory_bytes","groupname":"root","instance":"localhost:9256","job":"process_export_9256","memtype":"resident"},"values":[[1635991200,"300257280"],[1635993000,"302428160"],[1.12321,"301727744"]]}]}}`)
var p Person
err := json.Unmarshal(b, &p)
if err != nil {
fmt.Println(err)
}
wmd := p.Data.Values[0]["values"]
fmt.Println(wmd)
list := wmd.([]interface{})
//sum := float64(0)
for _, v := range list {
value := v.([]interface{})
for _, v := range value {
switch data := v.(type) {
case float64:
new := int64(data)
fmt.Printf("k is %d\n", new)
case string:
new1, _ := strconv.Atoi(data)
fmt.Println("v is :", new1)
}
}
}
}
```
有疑问加站长微信联系(非本文作者)