需求:遍历如下json 中 data的键值对,统计值的个数,比如下面的json格式中,100 出现了2次,200出现了1次
形式类似于{"name":"zhangsan","data":{"result0":100,"result1":200,"result2":300,"result3":400,"result5":100}}
请问下这个需求要如何处理?新手,网各位大神解答
```golang
package main
import (
"fmt"
"encoding/json"
)
const result = `{"name":"zhangsan","data":{"result0":100,"result1":200,"result2":300,"result3":400,"result5":100}}`
type Result struct {
Data map[string]int32 `json:"data"`
}
func main() {
var r Result
if err := json.Unmarshal([]byte(result), &r); err != nil {
panic(err)
}
statics := make(map[int32]int32)
for _, value := range r.Data {
statics[value] = statics[value] + 1
}
fmt.Println(statics)
}
```
#1