Golang parsing into struct
我无法将此 json 解析到我的结构中。谁能帮忙解决一下这个
1 | {"error":false,"response":{"results":[{"id":68876,"name":"cee lo green - big girls"},{"id":68954,"name":"charles, ray - the girl friend"},{"id":69603,"name":"charlie puth - la girls"},{"id":68001,"name":"city girls - careless"},{"id":68000,"name":"city girls - millionaire dick"},{"id":68002,"name":"city girls - period (we live)"},{"id":68004,"name":"city girls - rap shit"},{"id":68003,"name":"city girls - runnin"},{"id":68019,"name":"clairo - pretty girl"},{"id":68223,"name":"cohn, marc - girl of mysterious sorrow"},{"id":68343,"name":"contours, the - searching for a girl"} |
下面是我的结构
包主
导入 (
"编码/json"
"fmt"
"io/ioutil"
"日志"
"net/http")
类型测试结构{
SngID 字符串
SngNm 字符串
}
类型内部结构{
1 | Result[10] test `json:"results"` |
}
类型外部结构{
错误布尔
响应 [] 内部
}
您的 JSON 格式错误(检查 json.Unmarshal 返回的错误)。
无论如何,这个结构应该适合你。
1 2 3 4 5 6 7 8 9 | type Response struct { Error bool `json:"error"` Response struct { Results []struct { ID int `json:"id"` Name string `json:"name"` } `json:"results"` } `json:"response"` } |