L
L
levisl2015-10-31 05:18:48
go
levisl, 2015-10-31 05:18:48

How to force json in golang not to replace &?

q=20971520
f.Value = fmt.Sprintf("INTERNET?POSTpaid=%d/8&PREpaid=%d/8", q, q)
print f.Value, get what I want INTERNET?POSTpaid=20971520/8&PREpaid=20971520/8
marshal f, I get
"Value":"INTERNET?POSTpaid=20971520/8\u0026PREpaid=20971520/8"
I can't figure out how to escape. Or what to do in general
`json:",string"` does not help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey S., 2015-10-31
@Winsik

https://golang.org/pkg/encoding/json/#Marshal
"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."

A
akzhan, 2017-01-16
@akzhan

Either do a replacement of Unicode sequences in the result, or better, use JSON out of the box.
Look at https://github.com/mailru/easyjson for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question