英文:
syntax error: unexpected son, expecting semicolon, newline, or }
问题
当我在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字符,或者是否有任何设置可以更改这一点?
英文:
I got this error when I used normal keyboard for '
in json format as below.
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 }
and, then, I copied " ` " from stackOverflow and replaced with the original ones as below
type Movie struct {
Title string
Year int `json:"released"`
Color bool `json:"color,omitempty"`
Actors []string}
and, then, the syntax is gone
does GO file expect ' as unicode or is there any setting for that?
答案1
得分: 3
这两个是不同的字符:撇号(')和反引号(`)。Go语言使用反引号来进行结构体类型注释,也称为结构体标签。在你的例子中,它们被用来为encoding/json
包注释JSON键名。请参考这个问题了解如何输入它们。
英文:
These two are distinct characters: the apostrophe (') and backtick (`). The Go language uses backticks for struct type annotations, also called struct tags. In your example, they were used to annotate JSON key names for the encoding/json
package to use. See this question on how to input them.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论