此代码无效,响应将为空,例如{"test":""}
。
func main() {
router := gin.Default()
router.POST("/test", f
unc(c *gin.Context) {
test := c.Query("test")
c.JSON(200, gin.H{
"test": test,
})
})
router.Run()
}
更新:我通过struct找到了简单的解决方案:
func test(c *gin.Context) {
test := struct {
Test string `json:"test"`
Test2 string `json:"test2"`
}{}
c.BindJSON(&test)
c.JSON(200, gin.H{
"test1": test.Test,
"test2": test.Test2,
})
}
func test(c *gin.Context) {
test := struct {
Test string `json:"test"`
Test2 string `json:"test2"`
}{}
c.BindJSON(&test)
c.JSON(200, gin.H{
"test1": test.Test,
"test2": test.Test2,
})
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句