Add readme section about PureJSON

This commit is contained in:
Filip Figiel 2018-08-17 10:51:29 +02:00 committed by GitHub
parent 147b479dfc
commit 786a2132cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -812,6 +812,33 @@ func main() {
}
```
#### PureJSON
Normally, JSON replaces special HTML characters with their unicode entities, e.g. `<` becomes `\u003c`. If you want to encode such characters literally, you can use PureJSON instead.
```go
func main() {
r := gin.Default()
// Serves unicode entities
r.GET("/json", func(c *gin.Context) {
c.JSON(200, gin.H{
"html": "<b>Hello, world!</b>",
})
})
// Serves literal characters
r.GET("/purejson", func(c *gin.Context) {
c.PureJSON(200, gin.H{
"html": "<b>Hello, world!</b>",
})
})
// listen and serve on 0.0.0.0:8080
r.Run(":8080)
}
```
### Serving static files
```go