Skip to content

Instantly share code, notes, and snippets.

@sundy-li
Last active March 23, 2017 13:26
Show Gist options
  • Save sundy-li/ac1b83469d2f260ee66d3411aed25316 to your computer and use it in GitHub Desktop.
Save sundy-li/ac1b83469d2f260ee66d3411aed25316 to your computer and use it in GitHub Desktop.
json特殊字符串
Json中含有 特殊字符
String values encode as JSON strings coerced to valid UTF-8, replacing invalid bytes with the Unicode replacement rune. The angle brackets "<" and ">" are escaped to "\u003c" and "\u003e" to keep some browsers from misinterpreting JSON output as HTML. Ampersand "&" is also escaped to "\u0026" for the same reason. This escaping can be disabled using an Encoder with DisableHTMLEscaping.
方法1:
data := json.RawMessage(`"key": "http://www.baidu.com?a=c&b=d&e=d"`)
bytes, err := data.MarshalJSON()
方法2:
From go1.7
enc := json.NewEncoder(os.Stdout)
enc.SetEscapeHTML(false)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment