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

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -