首页 新闻 会员 周边 捐助

C#实体类动态传值问题在线求助:

0
悬赏园豆:15 [已解决问题] 解决于 2022-08-19 10:29
实体类:
public
class Sim2Model { public int uid { get; set; } public string password { get; set; } public int templateId { get; set; } public string extend { get; set; } public string customId { get; set; } public string time { get; set; } public SimObj[] _params { get; set; } } public class SimObj { public string mobile { get; set; } public string[] param { get; set; } }
复制代码
请求示例:
{
    "uid": 123456,
    "password": "d26a2abe1c51f401b37a14e400d33624f",
    "templateId": 12365,
    "extend": "86985",
    "customId": "121",
    "time":"2020-01-03 08:08:08",
    "params": [{
        "mobile": "15236521425",
            "param": ["tom", "上海"]
        },
        {
        "mobile": "15298741547",
            "param": ["cat", "北京"]
        }
    ]
}
复制代码

文本框中可能输入多个手机号用逗号分开,按照请求示例要求,params应该是个数组,根据这个结构应该怎么传值呢,有点懵

大da脸的主页 大da脸 | 初学一级 | 园豆:73
提问于:2022-08-16 21:00
< >
分享
最佳答案
0
public class Sim2Model
        {
            public int uid { get; set; }
            public string password { get; set; }
            public int templateId { get; set; }
            public string extend { get; set; }
            public string customId { get; set; }
            public string time { get; set; }
            public SimObj[] _params { get; set; }
        }

        public class SimObj
        {
            public string mobile { get; set; }
            public string[] param { get; set; }
        }

在Controller层,可以这样接收json参数,

        /// <summary>
        /// 创建Sim2Model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost()]
        [ProducesResponseType(typeof(ResponseInfo<bool>), 200)]
        public async Task<IActionResult> CreateChannel(Sim2Model model)
        {
            //ToDo
        }

推荐一个实战教程 《.NET Core 跨平台实战(附源码)》

收获园豆:15
楠木大叔 | 老鸟四级 |园豆:2081 | 2022-08-16 22:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册