https://blog.csdn.net/Aaron_80726/article/details/83870563
在app.conf配置文件中设置 copyrequestbody = true
在controller中使用Golang标准库json包来解析json数据封装到stuct结构体
package controllers
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego"
)
type UserController struct {
beego.Controller
}
type User struct {
Id string
Name string
Pwd string
}
func (this *UserController) AddUser() {
var user User
data := this.Ctx.Input.RequestBody
//json数据封装到user对象中
err := json.Unmarshal(data, &user)
if err != nil {
fmt.Println("json.Unmarshal is err:", err.Error())
}
fmt.Println(user)
this.Ctx.WriteString(user.Name)
}