【问题标题】:typed nested json decoding in go [duplicate]在go中键入嵌套的json解码[重复]
【发布时间】:2016-05-28 12:11:08
【问题描述】:

我尝试在 go 中解组一些嵌套的 JSON,结构沿着这个方向发展

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

我还在网上发布了running example

现在,当我使用 map[string]interface{} 来 Unmarshal 时,所有内容都会被反序列化。但是当我使用结构来 Unmarshal 时,我得到了 nil ,无论是结果还是错误。

怎么会?

【问题讨论】:

    标签: json data-structures go


    【解决方案1】:

    您要编组的所有结构字段都应以大写字母开头(公开)。这工作https://play.golang.org/p/ReCp3BAfTb

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      相关资源
      最近更新 更多