如果需要使用未知结构将XML文档转换为JSON,则可以使用goxml2json。
范例:
import ( // Other imports ... xj "github.com/basgys/goxml2json")func (u *UserResource) authenticateUser(request *restful.Request, response *restful.Response) { // Extract data from restful.Request xml := strings.NewReader(`<?xml version="1.0" encoding="UTF-8"?><app version="1.0"><request>1111</request></app>`) // Convert json, err := xj.Convert(xml) if err != nil { // Oops... } // ... Use JSON ...}注意:我是该库的作者。


![如何在Golang中将[] byte XML转换为JSON输出 如何在Golang中将[] byte XML转换为JSON输出](http://www.mshxw.com/aiimages/31/392048.png)
