add json ASCII string render (#1358)

add a json render that rendering json as ASCII string
This commit is contained in:
Rex Lee(李俊)
2018-07-03 17:17:08 +08:00
committed by Bo-Yi Wu
parent d17a12591f
commit 85221af84c
5 changed files with 101 additions and 0 deletions

View File

@ -900,6 +900,29 @@ func main() {
}
```
#### AsciiJSON
Using AsciiJSON to Generates ASCII-only JSON with escaped non-ASCII chracters.
```go
func main() {
r := gin.Default()
r.GET("/someJSON", func(c *gin.Context) {
data := map[string]interface{}{
"lang": "GO语言",
"tag": "<br>",
}
// will output : {"lang":"GO\u8bed\u8a00","tag":"\u003cbr\u003e"}
c.AsciiJSON(http.StatusOK, data)
})
// Listen and serve on 0.0.0.0:8080
r.Run(":8080")
}
```
### Serving static files
```go