package main
import (
"github.com/gin-gonic/gin"
)
type User struct {
Id int `json:"id"`
Name string `json:"name"`
Age int `json:"age"`
}
func main() {
router := gin.Default()
router.GET("/users", func(c *gin.Context) {
c.JSON(200, true) //true
c.JSON(200, gin.H{"msg" : "hello world!"}) //{"msg":"hello world!"}
c.JSON(200, &User{Id: 1, Name:"卷毛狒狒", Age:20}) //{"id":1,"name":"卷毛狒狒","age":20}
})
router.Run(":8080")
}
//{"user":{"age":"20","name":"juanmaofeifei"}}
原文:https://www.cnblogs.com/juanmaofeifei/p/14276868.html