【问题标题】:syntax error: unexpected son, expecting semicolon, newline, or }语法错误:意外的儿子,需要分号、换行符或 }
【发布时间】:2016-04-18 11:02:17
【问题描述】:

当我使用普通键盘输入' 时出现此错误,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 }

然后,我从 stackOverflow 复制了“`”并替换为原始的,如下所示

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

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

【问题讨论】:

  • 反引号位于键盘上的 Tab 键上方
  • 不是每个键盘,但我明白了。这个问题和答案对我帮助很大!谢谢大家!

标签: go


【解决方案1】:

这两个是不同的字符:撇号 (') 和反引号 (`)。 Go 语言使用反引号表示结构类型注释,也称为结构标记。在您的示例中,它们用于注释要使用的 encoding/json 包的 JSON 键名。输入方法见this question

【讨论】:

  • 哦,GoLang 使用反引号。谢谢你的邮件。
猜你喜欢
  • 2016-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-09
相关资源
最近更新 更多