beego controller响应json时如何忽略空值:如
```
{
"Id": 0,
"Account": "admin",
"Password": "",
"RoleId": 0,
"Status": "",
"CreateTime": "0001-01-01T00:00:00Z",
"CreateUserId": 0,
"UpdateTime": "0001-01-01T00:00:00Z",
"UpdateUserId": 0
}
```
零值数据不返回 只返回 `{“Account”:"admin"}`
代码:
```
func (this *AdminManageController) GetCurrentSysAdmin() {
var uid = this.GetSession("uid")
this.Ctx.Output.JSON(entity.SysAdmin{Account:uid.(string)}, true, false)
}
```
更多评论
在对应的实体中,加上 tag: ",omitempty" 。参考: http://docs.studygolang.com/pkg/encoding/json/#Marshal
#1