go - Decoding json in Golang -
i cannot figure out what's wrong in code decode json. returns empty struct. go playground here: http://play.golang.org/p/k8wznlt5m0
package main import ( "encoding/json" "fmt" ) type apiparams struct { accesstoken string `json:access_token` tokentype string `json:token_type` expiresin int64 `json:expires_in` } func main() { data := `{ "access_token": "asdfasdf", "token_type": "bearer", "expires_in": 5173885 }` var apiparams apiparams err := json.unmarshal([]byte(data), &apiparams) if err != nil { fmt.println(err) } fmt.println(apiparams) }
add double quotes tags:
type apiparams struct { accesstoken string `json:"access_token"` tokentype string `json:"token_type"` expiresin int64 `json:"expires_in"` }
Comments
Post a Comment