I tried to "Unmarshal" json in golang, but it doesn't seem to be working. I get 0 printed out instead of 1. What am I doing wrong?
package main
import (
"fmt"
"encoding/json"
)
type MyTypeA struct {
a int
}
func main() {
var smthng MyTypeA
jsonByteArray := []byte(`{"a": 1}`)
json.Unmarshal(jsonByteArray, &smthng)
fmt.Println(smthng.a)
}
Two problems with your code.
func main
won't be executed.http://play.golang.org/p/lJixko1QML
type MyTypeA struct {
A int
}
func main() {
var smthng MyTypeA
jsonByteArray := []byte(`{"a": 1}`)
json.Unmarshal(jsonByteArray, &smthng)
fmt.Println(smthng.A)
}