Unmarshal JSON data of unknown format [duplicate]

爱⌒轻易说出口 提交于 2019-11-29 18:52:23
  • If you don't know the keys, you can use map[string]interface{} to unmarshal your JSON payload.
  • If you use json:"-" tag for the struct fields, those fields will be ignored during JSON Marshal/Unmarshal.

You can try following options: Go Playground link

Option 1:

var grades map[string]interface{}

err := json.Unmarshal([]byte(jsonString), &grades)
fmt.Println(err)

fmt.Printf("%#v\n", grades)

Option 2: if you want have struct

var gradesData GradeData
err := json.Unmarshal([]byte(jsonString), &gradesData.Grades)
fmt.Println(err)

fmt.Printf("%#v\n", gradesData)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!