beego 获取 Request Body 里的内容

在 API 的开发中,我们经常会用到 JSON 或 XML 来作为数据交互的格式,如何在 beego 中获取 Request Body 里的 JSON 或 XML 的数据呢?

在配置文件里设置 copyrequestbody = true
在 Controller 中

   func (this *ObejctController) Post() {
    var ob models.Object
    json.Unmarshal(this.Ctx.Input.RequestBody, &ob)
    objectid := models.AddOne(ob)
    this.Data["json"] = "{\"ObjectId\":\"" + objectid + "\"}"
    this.ServeJson()
}

猜你喜欢

转载自blog.csdn.net/txj236/article/details/78271995