dongqian5639 2018-05-02 14:44
浏览 97

嵌套JSON对象的验证

{
 "firstname": "sathish",
 "lastname": "kumar",
 "city": {
    "id": 12,
    "name": "coimbatore"
 },
 "referrals": [
    {
        "name": "vignesh",
        "mobile": "1234567890"
    },
    {
        "name": "melvin",
        "mobile": "1234567890"
    }
 ]
}

Above is my JSON request for creating new profile. I need to do validation for above JSON using Beego validation package

type ProfileForm struct {
 Firstname string `json:"firstname" valid:"Required"`
 Lastname  string `json:"lastname" valid:"Required"`
 City      struct {
    ID   int    `json:"id" valid:"Required"`
    Name string `json:"name" valid:"Required"`
 } `json:"city"`
 Referrals []struct {
    Name   string `json:"name" valid:"Required"`
    Mobile string `json:"mobile" valid:"Required"`
 } `json:"referrals"`
}

I need to know the how can write the validation for JSON request using struct in Beego. Let me know are the any package or tutorial for this kind of requirement.

In official beego documentation I didn't see anything matches my requirement.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!