PureJSON

通常,JSON 会用 Unicode 实体替换特殊的 HTML 字符,例如,< 会变成 \u003c。如果你想按原样对这些字符进行编码,可以使用 PureJSON。此功能在 Go 1.6 及更低版本中不可用。

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")
}
上次修改时间:2024 年 5 月 10 日:提升 GitHub 操作工作流 (#276) (4371021)