使用 AsciiJSON 生成具有转义的非 ASCII 字符的 ASCII-only JSON。 

asciijson.go 代码:

package main

import "net/http"
import "github.com/gin-gonic/gin"

func main() {
	r := gin.Default()

	r.GET("/someJSON", func(c *gin.Context) {
		data := map[string]interface{}{
			"lang": "GO语言",
			"tag":  "<br>",
		}
		c.AsciiJSON(http.StatusOK, data)
	})

	r.Run(":8080")
}

执行 go run asciijson.go 后访问 http://127.0.0.1:8080/someJSON,输出:

{"lang":"GO\u8bed\u8a00","tag":"\u003cbr\u003e"}