2 回答

TA貢獻1808條經驗 獲得超4個贊
、等字段不是數組,它們是像數組一樣組織的 JSON 對象measured
。indicated
利用
Measured map[string]HTTPMineral
然后通過使用data.Measured["0"]
而不是獲取項目data.Measured[0]

TA貢獻1802條經驗 獲得超6個贊
Key Indicated、Inferred 和 Total 不是數組類型,它們是關聯數組(以鍵名作為索引)。
type HTTPMineral struct {
Symbol string `json:"symbol"`
Grade string `json:"grade"`
GradeUnit string `json:"grade_unit"`
Contained string `json:"contained"`
ContainedUnit string `json:"contained_unit"`
}
type SHttpMineral map[string]HTTPMineral
type PHttpMineral struct {
IHttpMineral
Value string `json:"value"`
Unit string `json:"unit"`
}
type HTTPResource struct {
Ticker string `json:"ticker"`
ResourceName string `json:"resource_name"`
DateOfRelease string `json:"dated"`
Measured PHttpMineral `json:"measured"`
Indicated PHttpMineral `json:"indicated"`
Inferred PHttpMineral `json:"inferred"`
Total PHttpMineral `json:"total"`
}
resource := &HTTPResource{}
if err := json.NewDecoder(r.Body).Decode(resource); err != nil {
log.Println("unmarshaling error ", err)
}
fmt.Println("Decodedresource")
- 2 回答
- 0 關注
- 122 瀏覽
添加回答
舉報