3

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

qwertmax
  • 3,120
  • 2
  • 29
  • 42
  • As soon as I made a post, stackoverflow highlighted the go code, it immediately made me think about the exported and not exported values – qwertmax Mar 22 '15 at 11:16

1 Answers1

10

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
qwertmax
  • 3,120
  • 2
  • 29
  • 42