我正在尝试解组以下 XML,但收到错误. ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"ItemsItemASINB005XSS8VC/ASIN/Item/Items 这是我的结构: type Product struct { XMLName xml.Name `xm
<ItemSearchResponse xmlns="http://webservices.amazon.com/AWSECommerceService/2011-08-01"> <Items> <Item> <ASIN>B005XSS8VC</ASIN> </Item> </Items>
这是我的结构:
type Product struct { XMLName xml.Name `xml:"Item"` ASIN string } type Result struct { XMLName xml.Name `xml:"ItemSearchResponse"` Products []Product `xml:"Items"` }
错误的文本是“预期的元素类型< Item>但是< Items>”,但我看不出我出错的地方.任何帮助表示赞赏.
v := &Result{Products: nil} err = xml.Unmarshal(xmlBody, v)这对我有用(请注意Items> Item):
type Result struct { XMLName xml.Name `xml:"ItemSearchResponse"` Products []Product `xml:"Items>Item"` } type Product struct { ASIN string `xml:"ASIN"` }