为xml创建结构时遇到问题
到这里来。。。我知道我的结构有问题,但似乎无法让它工作。。。。非常感谢任何建议为xml创建结构时遇到问题,xml,go,Xml,Go,到这里来。。。我知道我的结构有问题,但似乎无法让它工作。。。。非常感谢任何建议 <?xml version='1.0' ?> <result called_on="2015-06-17 12:49:41.014435+00"> <entities count="0" start="0"> <entity name="Aaron Test" id="12345" type="organization" /> <entity
<?xml version='1.0' ?>
<result called_on="2015-06-17 12:49:41.014435+00">
<entities count="0" start="0">
<entity name="Aaron Test" id="12345" type="organization" />
<entity name="MagicOne" id="102301" type="organization" />
</entities>
<status code="ok" />
</result>
type OrgResult struct {
XMLName xml.Name `xml:"result"`
Entities OrgEntities `xml:"entity"`
}
type OrgEntities struct {
Org OrgEntity `xml:"entity"`
}
type OrgEntity struct {
ID int `xml:"id,attr"`
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
}
OrgResult := OrgResult{}
xml.Unmarshal(body, &OrgResult)
fmt.Println(body)
fmt.Println(OrgResult)
类型OrgResult结构{
XMLName xml.Name`xml:“结果”`
实体OrgEntities`xml:“实体”`
}
类型OrgEntities结构{
Org OrgEntity`xml:“实体”`
}
类型OrgEntity结构{
ID int`xml:“ID,attr”`
名称字符串`xml:“名称,属性”`
类型字符串`xml:“类型,属性”`
}
OrgResult:=OrgResult{}
Unmarshal(body和OrgResult)
fmt.Println(车身)
格式打印项次(OrgResult)
明白了:)
明白了:)
typeorgResult结构{XMLName xml.Name`xml:“result”`Entities OrgEntities`xml:“Entities”`typeorgEntities结构{Org[]OrgEntity`xml:“entity”`}type OrgEntity结构{ID int`xml:“ID,attr”`Name string`xml:“Name,attr”`type string`xml:“type,attr”`
你应该把你的评论放在回答中,因为它的代码和它解决了你的问题problem@joelgoldstick谢谢你的提醒
type OrgResult struct {
XMLName xml.Name `xml:"result"`
Entities OrgEntities `xml:"entities"`
}
type OrgEntities struct {
Org []OrgEntity `xml:"entity"`
}
type OrgEntity struct {
ID int `xml:"id,attr"`
Name string `xml:"name,attr"`
Type string `xml:"type,attr"`
}