简体   繁体   English

"具有未知键的 Unmarshall JSON 上的空结构"

[英]Empty struct on Unmarshall JSON with unknown key

I'm getting from and API a JSON like the following:我从 API 获取如下 JSON:

{
  "unknownkey" : {
    "sum" : 7030.76636,
    "low" : 6787.05692,
    "avg" : 0.00014
  }
}

You may use a map with value type being Result<\/code> or *Result<\/code> :您可以使用值类型为Result<\/code>或*Result<\/code>的地图:

var wrapper map[string]Result

if err := json.Unmarshal([]byte(body), &wrapper); err != nil {
    panic(err)
}

fmt.Printf("%+v\n", wrapper)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM