gin返回json假数据

package main

import (
	"github.com/gin-gonic/gin"

	"encoding/json"
	"fmt"
)
func main() {
	router := gin.Default()
	router.GET("/test2", test2)

	router.Run(":8080")
}

func test2(c *gin.Context) {
	var result interface{}
	list := `
				    [
        {
            "value": "weixin",
            "message": "微信公众号"
        },
        {
            "value": "weixin_xcx",
            "message": "微信小程序"
        },
        {
            "value": "ali_xcx",
            "message": "支付宝小程序"
        },
        {
            "value": "app",
            "message": "手机端APP应用"
        }
    ]
				`
	err := json.Unmarshal([]byte(list), &result)
	if err!=nil{
		fmt.Println(err)
	}
	c.JSON(200,gin.H{
		"code":200,
		"msg":"success",
		"data":result,
	})
}

返回参数:

{
    "code":200,
    "data":[
        {
            "message":"微信公众号",
            "value":"weixin"
        },
        {
            "message":"微信小程序",
            "value":"weixin_xcx"
        },
        {
            "message":"支付宝小程序",
            "value":"ali_xcx"
        },
        {
            "message":"手机端APP应用",
            "value":"app"
        }
    ],
    "msg":"success"
}
上一篇:【offerMe--面经必备】---腾讯面经分享(包含答案)


下一篇:一篇文章让你了解什么是art-template模板引擎