发生这种情况是因为其他包(
encoding/json)无法访问私有字段(即使具有反射)。在私有语言中,私有字段是以小写字母开头的字段。要解决此问题,请使您的结构包含公共字段(以大写字母开头):
type jsonStruct struct { Main struct { Data []struct { Key1 string `json:"KEY1"` Key2 string `json:"KEY2"` Key3 int `json:"KEY3"` Key4 string `json:"KEY4"` Key5 string `json:"KEY5"` Key6 string `json:"KEY6"` Key7 string `json:"KEY7"` } `json:"data"` } `json:"MAIN"`}https://play.golang.org/p/lStXAvDtpZ



