Go
- 1 ответ
- 0 вопросов
1
Вклад в тег
type Rewards struct {
XMLName xml.Name `xml:"rewards"`
Rewards []Reward `xml:"reward"`
}
type Reward struct {
Value string
Attrs map[string]string
}
func (r *Reward) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
r.Attrs = make(map[string]string)
for _, attr := range start.Attr {
r.Attrs[attr.Name.Local] = attr.Value
}
if err := d.DecodeElement(&r.Value, &start); err != nil {
return err
}
return nil
}
// ...
var obj Rewards
if err := xml.Unmarshal(data, &obj); err != nil {
log.Fatal(err)
}
log.Printf("%+v", obj.Rewards)
[{Value:100 Attrs:map[type:money slot:101 repeated:1]} {Value:1 Attrs:map[bagId:1 repeated:1 type:freedomBagsExp]} {Value:30 Attrs:map[repeated:1 type:rating]} {Value:1 Attrs:map[repeated:1 type:key key_id:2]} {Value:30 Attrs:map[type:guildAP repeated:1]} {Value:2 Attrs:map[key_id:2 repeated:1 type:key]} {Value:476 Attrs:map[repeated:1 type:rating]}]