From 9ea9e0fd5178d0e28d79ca2f594e1cb1fb962e9f Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Wed, 2 Jul 2014 11:47:55 +0200 Subject: [PATCH 1/2] Fix JSON Struct example --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index baebc795..1239620f 100644 --- a/README.md +++ b/README.md @@ -190,12 +190,15 @@ func main() { r.GET("/moreJSON", func(c *gin.Context) { // You also can use a struct var msg struct { + Name string Message string - Status int + Number int } + msg.Name = "Lena" msg.Message = "hey" - msg.Status = 200 - c.JSON(200, msg.Status) + msg.Number = 123 + // Will output : {"Name": "Lena", "Message": "hey", "Number": 123} + c.JSON(200, msg) }) r.GET("/someXML", func(c *gin.Context) { From 406a509fa3626fa6f20c7a6e73699ef15a22facd Mon Sep 17 00:00:00 2001 From: Javier Provecho Date: Wed, 2 Jul 2014 11:53:45 +0200 Subject: [PATCH 2/2] Extra example --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1239620f..8a051d05 100644 --- a/README.md +++ b/README.md @@ -190,14 +190,15 @@ func main() { r.GET("/moreJSON", func(c *gin.Context) { // You also can use a struct var msg struct { - Name string + Name string `json:"user"` Message string Number int } msg.Name = "Lena" msg.Message = "hey" 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) })