Extra example
This commit is contained in:
parent
9ea9e0fd51
commit
406a509fa3
@ -190,14 +190,15 @@ func main() {
|
|||||||
r.GET("/moreJSON", func(c *gin.Context) {
|
r.GET("/moreJSON", func(c *gin.Context) {
|
||||||
// You also can use a struct
|
// You also can use a struct
|
||||||
var msg struct {
|
var msg struct {
|
||||||
Name string
|
Name string `json:"user"`
|
||||||
Message string
|
Message string
|
||||||
Number int
|
Number int
|
||||||
}
|
}
|
||||||
msg.Name = "Lena"
|
msg.Name = "Lena"
|
||||||
msg.Message = "hey"
|
msg.Message = "hey"
|
||||||
msg.Number = 123
|
msg.Number = 123
|
||||||
// Will output : {"Name": "Lena", "Message": "hey", "Number": 123}
|
// Note that msg.Name becomes "user" in the JSON
|
||||||
|
// Will output : {"user": "Lena", "Message": "hey", "Number": 123}
|
||||||
c.JSON(200, msg)
|
c.JSON(200, msg)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user