语法错误:意外的儿子,期待分号,换行符或}

时间:2016-04-17 12:21:52

标签: go

当我使用json格式的'的普通键盘时,我遇到了这个错误。

type Movie struct {
Title   string
Year    int     'json:"released"'
Color   bool    'json:"color,omitempty"'
Actors  []string}

`-go run * ----> :syntax error: unexpected son, expecting semicolon, newline, or }

然后,我复制了#34; `"来自stackOverflow并替换为原来的

type Movie struct {
Title   string
Year    int     `json:"released"`
Color   bool    `json:"color,omitempty"`
Actors  []string}    

然后,语法消失了:( GO文件是否期望'作为unicode还是有任何设置?

1 个答案:

答案 0 :(得分:1)

这两个是不同的字符:撇号(')和反引号(`)。 Go语言使用反引号作为结构类型注释,也称为结构标记。在您的示例中,它们用于为要使用的encoding/json包注释JSON密钥名称。请参阅this question了解如何输入它们。

相关问题