英文:
Struct for JSON objects in GO
问题
我正在学习GO语言,当定义用于处理JSON的结构体时,像下面这样。
type List struct {
ID string `datastore:"-"`
Name string
}
我注意到在 ` 符号之间有这段文本。我还没有找到解释它的含义的说明。
即使没有这些文本,事情似乎也能正常工作。
英文:
I'm learning GO and when defining structs for working with JSON like below.
type List struct {
ID string `datastore:"-"`
Name string
}
I see that there is this text in between ` sign. I have not been able to find an explanation what that signifies.
Things seem to work even without those.
答案1
得分: 3
这些是用于将Go结构体编组为JSON的结构标签。在JSON中,与Go不同,字段是小写字符串。因此,大多数情况下会这样使用:
type List struct {
ID string `json:"id"`
Name string `json:"name"`
}
在JSON中:
{
"id": "some id",
"name": "some name"
}
在这里查看帖子here。
英文:
They are struct tags used in Marshal'ing Go struct into JSON. In JSON, unlike Go, fields are in lowercase strings. Therefore, most use cases would be
type List struct {
ID string `json:"id"`
Name string `json:"name"`
}
In JSON
{
"id": "some id",
"name": "some name"
}
See post here
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论