转到json.取消编组不起作用



我有json,它没有被解码为struct。

我知道我代码中的某个错误,但我被卡住了,不知道错误在哪里,我做错了什么

请帮帮我,这是我的代码:

type GOOGLE_JSON struct {
    code        string `json:"code"`
    clientId    string `json:"clientId"`
    redirectUri string `json:"redirectUri"`
}
body := []byte(`{"code":"111","clientId":"222","redirectUri":"333"}`)
//google_json := GOOGLE_JSON{}
var google_json GOOGLE_JSON
err := json.Unmarshal(body, &google_json)
if err != nil {
    fmt.Println(err)
}
fmt.Println(google_json)

此处的示例

我发现错误

    type GOOGLE_JSON struct {
        code        string `json:"code"`
        clientId    string `json:"clientId"`
        redirectUri string `json:"redirectUri"`
    }

必须是大写字母

    type GOOGLE_JSON struct {
        Code        string `json:"code"`
        ClientId    string `json:"clientId"`
        RedirectUri string `json:"redirectUri"`
    }

我注意力不集中

Code // <- exported
ClientId // <- exported
RedirectUri // <- exported
code // <-- not exported
clientId // <-- not exported
redirectUri // <-- not exported

最新更新