i try to put json data to web, i use json.Marshal
to create json data.
Flowing picture is fmt.Println(string(jsonOut))
result
i use template.HTMLEscape(w, []byte(jsonOut))
to show in web, it will show like following picture.
the "
become "
.
why it will show "
and how can i do for show "
?
template.HTMLEscape
will escape special character.
use following code can post json data to web
w.Header().Set("Content-Type", "application/json")
w.Write(jsonOut)
reference https://www.alexedwards.net/blog/golang-response-snippets#json
If you just want show json in the http response
w.Write(jsonOut)
If you want to show json in html
t, _ := template.New("foo").Parse(`<head></head><body>{{$.data}}</body>`)
_ = t.Execute(w, map[string]string{
"data": string(jsonOut),
})