forked from mirror/gin
Merge pull request #21 from javierprovecho/master
Fix JSON Struct example
This commit is contained in:
commit
3bfbf986a2
10
README.md
10
README.md
|
@ -190,12 +190,16 @@ func main() {
|
|||
r.GET("/moreJSON", func(c *gin.Context) {
|
||||
// You also can use a struct
|
||||
var msg struct {
|
||||
Name string `json:"user"`
|
||||
Message string
|
||||
Status int
|
||||
Number int
|
||||
}
|
||||
msg.Name = "Lena"
|
||||
msg.Message = "hey"
|
||||
msg.Status = 200
|
||||
c.JSON(200, msg.Status)
|
||||
msg.Number = 123
|
||||
// Note that msg.Name becomes "user" in the JSON
|
||||
// Will output : {"user": "Lena", "Message": "hey", "Number": 123}
|
||||
c.JSON(200, msg)
|
||||
})
|
||||
|
||||
r.GET("/someXML", func(c *gin.Context) {
|
||||
|
|
Loading…
Reference in New Issue