英文:
Golang Unmarshal XML attributes
问题
我正在尝试从XML中获取一些属性值,但没有成功。
http://play.golang.org/p/a5IqjbH3DV
有人能看出我做错了什么吗?
英文:
I'm trying to get some attribute values out of XML, but without success.
http://play.golang.org/p/a5IqjbH3DV
Can anyone spot of what I'm doing wrong?
答案1
得分: 8
字段应该被导出(以大写字母开头)。
你对Entry
的处理是正确的,但对Statistics
结构体的处理不正确。
参见:http://play.golang.org/p/cQRGJag313
type Statistics struct {
TotalUploadViews int `xml:"totalUploadViews,attr"`
SubscriberCount int `xml:"subscriberCount,attr"`
}
英文:
The fields should be exported ( start with uppercase )
You did it right for the Entry
but not for the Statistics
struct
See: http://play.golang.org/p/cQRGJag313
type Statistics struct {
TotalUploadViews int `xml:"totalUploadViews,attr"`
SubscriberCount int `xml:"subscriberCount,attr"`
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论