第一种
func Login(c *gin.Context) {
json := make(map[string]interface{}) //注意该结构接受的内容
c.BindJSON(&json)
log.Printf("%v",&json)
c.JSON(http.StatusOK, gin.H{
"name": json["name"],
"password": json["password"],
})
}
第二种
type User struct {
Name string `json:"name"`
Password int64 `json:"password"`
}
func Login(c *gin.Context) {
json := User{}
c.BindJSON(&json)
log.Printf("%v",&json)
c.JSON(http.StatusOK, gin.H{
"name": json.Name,
"password": json.Password,
})
}

这篇博客探讨了使用Gin框架处理HTTP请求时,两种不同的JSON绑定技术。第一种方法是将JSON解析为map[string]interface{}

8832

被折叠的 条评论
为什么被折叠?



