使用 toml 解析器 ( https://github.com/BurntSushi/toml )
我正在尝试解组以下 toml 文件:
type (
fruitSpecs struct {
Id int `toml:"id"`
Name string `toml:"name"`
}
)
blob := `
[kiwi]
id = 1234581941
name = "kiwi"
`
o := &fruitSpecs{}
err := toml.Unmarshal([]byte(blob), o)
fmt.Println(o.Id)
好像当我使用表格时[kiwi]似乎无法正确解组它。
如果去掉表名,就可以成功抓取Id字段。
在尝试成功构建将保存数据的整个结构时,我缺少一些封装吗?
我尝试了以下方法来添加表名,但没有任何积极的结果:
type (
fruitSpecs struct {
Id int `toml:"id"`
Name string `toml:"name"`
}
fruits struct {
fruit fruitSpecs
}
)
blob := `
[kiwi]
id = 1234581941
name = "kiwi"
`
o := &fruitSpecs{}
err := toml.Unmarshal([]byte(blob), o)
fmt.Println(o.Id)
但它的错误是: o.Id undefined (type *fruitSpecs has no field or method Id)
慕工程0101907
相关分类