mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-23 10:02:10 +08:00
Add readme section about PureJSON
This commit is contained in:
parent
147b479dfc
commit
786a2132cb
27
README.md
27
README.md
@ -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
|
### Serving static files
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
Loading…
x
Reference in New Issue
Block a user