Go实战--xml与json相互转换(The way to go)

我会带着你远行 2022-06-16 02:19 952阅读 0赞

生命不止,继续 go go go !

之前写了两篇博客,分别介绍了go中的encoding/json和encoding/xml,有很多相识之处。

json和xml的恩恩怨怨还没有结束,在实战中我们会用到XML与json的相互转化,没有太难懂的地方。

xml转json

  1. package main
  2. import (
  3. "encoding/json"
  4. "encoding/xml"
  5. "fmt"
  6. )
  7. type DataFormat struct {
  8. ProductList []struct {
  9. Sku string `xml:"sku" json:"sku"`
  10. Quantity int `xml:"quantity" json:"quantity"`
  11. } `xml:"Product" json:"products"`
  12. }
  13. func main() {

发表评论

表情:
评论列表 (有 0 条评论,952人围观)

还没有评论,来说两句吧...

相关阅读