0

I try to Unmarshal some nested JSON in go, the structs go something along this

type GameState struct {
  missiles []*Missile
  others   []*Player
  you      *Player
}
type Message struct {
  gamestate   *GameState
  messagetype string
}
// json like {"gamestate":{...},"messagetype":"stateupdate"}

I've also put a running example online.

Now when I use map[string]interface{} to Unmarshal everything gets deserialized. But the moment I use the structs to Unmarshal I get nil back, both as result and error.

How come?

santa
  • 983
  • 9
  • 30

1 Answers1

2

All struct fields you want to marshal should start with uppercase letter (be public). This works https://play.golang.org/p/ReCp3BAfTb

creker
  • 9,400
  • 1
  • 30
  • 47