douyamitong57935
2015-02-18 23:04
浏览 224
已采纳

如何阻止json.Marshal转义<和>?

package main

import "fmt"
import "encoding/json"

type Track struct {
    XmlRequest string `json:"xmlRequest"`
}

func main() {
    message := new(Track)
    message.XmlRequest = "<car><mirror>XML</mirror></car>"
    fmt.Println("Before Marshal", message)
    messageJSON, _ := json.Marshal(message)
    fmt.Println("After marshal", string(messageJSON))
}

Is it possible to make json.Marshal not escape < and >? I currently get:

{"xmlRequest":"\u003ccar\u003e\u003cmirror\u003eXML\u003c/mirror\u003e\u003c/car\u003e"}

but I am looking for something like this:

{"xmlRequest":"<car><mirror>XML</mirror></car>"}

5条回答 默认 最新

相关推荐 更多相似问题