dongzou7134 2017-02-22 08:11
浏览 47
已采纳

Golang结构字段名称并解组到此结构中

I wrote an example program to illustrate my question, and it can be viewed here: https://play.golang.org/p/6776lYcbBR

So my question is:

when a structure (GameOne) field's name starts with a capital letter, json.Unmarshal works as expected; when it starts with a lower-case letter (GameTwo), the field value is set to its default.

Why is this so? Has it something to do with scope/visibility rules?

Thank you in advance.

  • 写回答

2条回答 默认 最新

  • dongqia0240 2017-02-22 08:27
    关注

    json.Unmarshal sets only the export fields in a struct and for exporting a field the first letter must be capital.
    For more information I highly suggest you to take a look to the documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?