Extra example

This commit is contained in:
Javier Provecho 2014-07-02 11:53:45 +02:00
parent 9ea9e0fd51
commit 406a509fa3
1 changed files with 3 additions and 2 deletions

View File

@ -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)
}) })