【发布时间】:2019-04-01 03:48:03
【问题描述】:
我在 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
请帮我解决问题。根据图书馆的文件,我找不到错误。
【问题讨论】:
-
person 是代码中的字符串,而不是结构。如果您将 JSON 解组为结构值,则模板代码可以使用反射来访问 id 等字段。
标签: go go-templates