我從服務收到具有此格式的 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 關注
- 173 瀏覽
添加回答
舉報
0/150
提交
取消