Go实战--xml与json相互转换(The way to go)
生命不止,继续 go go go !
之前写了两篇博客,分别介绍了go中的encoding/json和encoding/xml,有很多相识之处。
json和xml的恩恩怨怨还没有结束,在实战中我们会用到XML与json的相互转化,没有太难懂的地方。
xml转json
package main
import (
"encoding/json"
"encoding/xml"
"fmt"
)
type DataFormat struct {
ProductList []struct {
Sku string `xml:"sku" json:"sku"`
Quantity int `xml:"quantity" json:"quantity"`
} `xml:"Product" json:"products"`
}
func main() {
还没有评论,来说两句吧...