简体   繁体   中英

go json.Unmarshal do not working

I have json which is not decoded to struct.

I know that error somewhere in my code, but I'm stuck and do not know where the error is and what am I doing wrong

Help me please, here is my code:

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)

example here

I've found error

was

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

must be capital letters

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

I was inattentive

Code // <- exported
ClientId // <- exported
RedirectUri // <- exported

code // <-- not exported
clientId // <-- not exported
redirectUri // <-- not exported

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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