繁体   English   中英

Golang 解析为结构体

[英]Golang parsing into struct

我无法将此 json 解析为我的结构。 任何人都可以帮忙解决这个问题

{"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"}

下面是我的结构包主要

导入 ( "encoding/json" "fmt" "io/ioutil" "log" "net/http")

type test struct{ SngID string json:"id" SngNm string json:"name" } type Inner struct{

Result[10] test `json:"results"`

}

type Outer struct{ Eror bool json:"error" Response [] Inner json:"results"

}

您的 JSON 格式错误(检查 json.Unmarshal 返回的错误)。

无论如何,这个结构应该适合你。

    type Response struct {
        Error    bool `json:"error"`
        Response struct {
            Results []struct {
                ID   int    `json:"id"`
                Name string `json:"name"`
            } `json:"results"`
        } `json:"response"`
    }

暂无
暂无

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

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