大神帮忙看看我这个程序的问题出在哪里了?总是差一些解析不出来正确的结果。
```
package main
import (
"encoding/json"
"fmt"
)
type hisData struct {
Ms string `json:"Ms"`
Time string `json:"Time"`
Value string `json:"Value"`
}
func main() {
str := `{
"SF2WT.x1_zjs_sfc_ps20kt_4-5_100-1239_pv:1": [
{
"Ms": 0,
"Value": "0",
"Time": "2019/11/28 10:00:21.000"
},
{
"Ms": 0,
"Value": "68.75",
"Time": "2019/11/28 10:00:59.000"
},
{
"Ms": 0,
"Value": "39.375",
"Time": "2019/11/28 10:01:01.000"
}
],
"SF2WT.x1_zjs_sfc_ps20kt_4-5_100-1239_sum:1": [
{
"Ms": 0,
"Value": "14.6875",
"Time": "2019/11/28 10:01:03.000"
},
{
"Ms": 0,
"Value": "9.0625",
"Time": "2019/11/28 10:01:05.000"
},
{
"Ms": 0,
"Value": "6.25",
"Time": "2019/11/28 10:01:07.000"
},
{
"Ms": 0,
"Value": "12.5",
"Time": "2019/11/28 10:01:09.000"
}
]
}`
type mp map[string][]hisData
var v mp
json.Unmarshal([]byte(str), &v)
fmt.Println(fmt.Sprintf("%+v", v))
}
```
运行后的结果是:
map[SF2WT.x1_zjs_sfc_ps20kt_4-5_100-1239_pv:1:[{Ms: Time:2019/11/28 10:00:21.000 Value:0} {Ms: Time:2019/11/28 10:00:59.000 Value:68.75} {Ms: Time:2019/11/28 10:01:01.000 Value:39.375}] SF2WT.x1_zjs_sfc_ps20kt_4-5_100-1239_sum:1:[{Ms: Time:2019/11/28 10:01:03.000 Value:14.6875} {Ms: Time:2019/11/28 10:01:05.000 Value:9.0625} {Ms: Time:2019/11/28 10:01:07.000 Value:6.25} {Ms: Time:2019/11/28 10:01:09.000 Value:12.5}]]
有疑问加站长微信联系(非本文作者)