我从服务收到具有此格式的 JSON。{ "result": { "bn05deh7jsm86gtlg2l0C": [ { "index_name": "BASE", "index_value": 4081512, "timestamp": "2019-11-05T13:20:00Z", "op_id": "A0000000001" }, ... ], "bn05deh7jsm86gtlg2lgC": [ { "index_name": "BASE", "index_value": 4728633, "timestamp": "2019-11-05T13:20:00Z", "op_id": "A0000000001" }, ... ], ... }}我需要的是将其转换为像 []Measure 这样的对象数组:type Measure struct { IndexName string `json:"index_name"` IndexValue uint32 `json:"index_value"` Timestamp time.Time `json:"timestamp"` OperationID string `json:"op_id"` Guid string `json:"guid"`}哪里Guid应该有价值bn05deh7jsm86gtlg2l0C,bn05deh7jsm86gtlg2lgC等等。这是我的代码:url := "https://myurl.com"req, err := http.NewRequest("GET", url, nil)if req != nil { req.Header.Set("Content-Type", "application/json")}resp, err := client.Do(req)if err != nil { log.Println(err) return nil}var measures []Measureerr = json.NewDecoder(resp.Body).Decode(&measures)if err != nil { log.Println(err)}我怎样才能做到这一点?
- 2 回答
- 0 关注
- 129 浏览
添加回答
举报
0/150
提交
取消