在使用 Golang 开发项目时,经常需要请求第三方 API 接口,返回的数据结构是 json 格式,请求的结果需要解析到结构体 struct 中,方便后续使用。
在使用 json.Unmarshal 时,需要事先定义结构体,如果 json 结构复杂的话觉得麻烦。有没有一种快速的方法可以根据 json 定义 struct ?

在线 json 生成 go 结构体 struct 工具
网址:https://mholt.github.io/json-to-go/

使用方法:在左侧输入 json 字符即可自动生成 struct
json 生成 struct 结果
json 生成 struct 结果

如果 json 结构很简单时,推荐使用 go-simplejson

标签: Go