如何在Golang中将Json字符串转换为xml?
问题描述:
I'm trying to convert json string in to xml format using Golang. My whole object is to convert json in to map string interface and then convert interface in to xml file. (There is no predefined structs). Please help me to solve this issue?
var f interface{}
err := json.Unmarshal(b, &f)
答
There's an xml package that is equivalent to the json one under encoding. Just import it and then marshal the result of your json.Unmarshal
import "encoding/xml"
xml.Marshal(&f)