我需要解組的 XML 格式如下:data := `<table> <name> <code>23764</code> <name>Smith, Jane</name> </name> <name> <code>11111</code> <name>Doe, John</name> </name></table>`我嘗試了以下結(jié)構(gòu)和代碼無濟(jì)于事:type Customers struct { XMLName xml.Name `xml:"table"` Custs []Customer}type Customer struct { XMLName xml.Name `xml:"name"` Code string `xml:"code"` Name string `xml:"name"`}...var custs Customerserr := xml.Unmarshal([]byte(data), &custs)if err != nil { fmt.Printf("error: %v", err) return}fmt.Printf("%v", custs)for _, cust := range custs.Custs { fmt.Printf("Cust:\n%v\n", cust)}范圍沒有打印出來,打印custs只給我{{ table} []}
- 1 回答
- 0 關(guān)注
- 193 瀏覽
添加回答
舉報
0/150
提交
取消