使用 SecureJSON 防止 json 劫持。如果给定的结构是数组值,则默认预置 while(1);
到响应体。
secruejson.go:
package main
import "github.com/gin-gonic/gin"
func main() {
r := gin.Default()
r.GET("/someJSON", func(c *gin.Context) {
names := []string{"lena", "austin", "foo"}
c.SecureJSON(200, names)
})
r.Run(":8080")
}
相关阅读:Why does Google prepend while(1); to their JSON responses?