go语言获取数据一般用GetInt,GetString,但是小程序那边提交的数据一般是json,用beego框架获取数据需要配置copyrequestbody = true
然后获取c.Ctx.Input.RequestBody
json.Unmarshal(c.Ctx.Input.RequestBody, &form)
代码如下:
func (c *NsOrderController) SaveOrder() {
//var v models.NsOrder
type FormData struct {
BusinessMessage string `form:"businessMessage"`
FormId string `form:"formId"`
Sign string `form:"sign"`
Time string `form:"time"`
GoodsJsonStr string `form:"goodsJsonStr"`
ReceiverInfoId int `form:"receiverInfoId"`
}
var form FormData
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &form); err == nil {
fmt.Println(form)//这里可以看到数据
} else {
c.Data["json"] = err.Error()
}
c.ServeJSON()
}
!!!注意:struct里面的字段首字母要大写,否则获取不到数据