【go】beego json.Unmarshal is err: unexpected end of JSON input无法获取到数据
func (this*UserController)RetData(resp map[string]interface{}) {
this.Data["json"] =respthis.ServeJSON()
}
func (this*UserController)RegHtml() {
this.TplName = "reg.html"
}
func (this*UserController)Reg() {
resp := make(map[string]interface{})defer this.RetData(resp)
err :=json.Unmarshal(this.Ctx.Input.RequestBody,&resp)
//resp["errno"] =4001
//resp["errmsg"] ="查询失败"
//this.RetData(resp)
//beego.Info("mobile",resp["mobile"],resp)
//beego.Info("password",resp["password"])
//beego.Info("sms_code",resp["sms_code"])
o :=orm.NewOrm()
user := models.User{}
if err != nil {
fmt.Println("json.Unmarshal is err:", err.Error())
}### 问题描述
问题出现的环境背景及自己尝试过哪些方法
相关代码
// 请把代码文本粘贴到下方(请勿用图片代替代码)
你期待的结果是什么?实际看到的错误信息又是什么?
看了下源码,你调用的this.Ctx.Input.RequestBody
是需要调用this.Ctx.Input.CopyBody()
之后才会赋值。
你可以看下他这个方法的实现,他也是从this.Ctx.Request.Body
这属性中复制内容并复制给RequestBody
的。
回答
以上是 【go】beego json.Unmarshal is err: unexpected end of JSON input无法获取到数据 的全部内容, 来源链接: www.h5w3.com/115060.html