I was playing around to learn how embedding works. http://play.golang.org/p/oHOim4G1-l
When I marshalled Child struct it marshals as {}
. Why does it marshal like this?
Your JSON dictionary is empty because none of the fields of the struct (or any of the structures embedded inside the struct) are exported .
If you change the field names to start with an upper case letter, then the encoding/json
module will be able to see them. Of course since you've also got methods called Name
and Value
, you'll need to call them something else to avoid a conflict.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.