无法评估类型字符串中的字段 <field>

Can't evaluate field <field> in type string

我在 golang 包中使用 text/template 来解析 json 字符串中带有环境的文本。

示例:https://play.golang.org/p/uARnrOyG4Th

但是我有一个错误:2009/11/10 23:00:00 Execute: template: Person template:1:19: executing "Person template" at <.id>: can't evaluate field id in type string

请帮我解决问题。我无法根据图书馆的文件找到错误。

模板不能直接应用于字符串,您应该创建一个结构,然后将您的 JSON 字符串解组为结构实例。 try the code