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 关注
- 105 浏览
添加回答
举报