简体   繁体   中英

Empty struct on Unmarshall JSON with unknown key

I'm getting from and API a JSON like the following:

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

You may use a map with value type being Result<\/code> or *Result<\/code> :

var wrapper map[string]Result

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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