donet (MVC)webAPI 的接受json 的操作

直接用对象来进行接收,这个方法还不错的。

csharp 复制代码
    public class BangdingWeiguiJiluController : ApiController
    {

        /// <summary>
        /// Json数据录入错误信息
        /// </summary>
        /// <param name="WeiguiInfos"></param>
        /// <returns></returns>

        [System.Web.Http.HttpPost]
        public JsonResult<ResultMsgWeb> WeiguiJiluAdd([FromBody]BangdingWeiguiJilu WeiguiInfos )
        {
            //BangdingWeiguiJilu modelInf = new BangdingWeiguiJilu() { SetDate= DateTime.Now,YuangongId= 2756,SetType=1,Creator = 9999999 };
            //string Infr = JsonConvert.SerializeObject(modelInf);
            ResultMsgWeb Msg = new ResultMsgWeb();  
            try
            {
                ResultMsg MsgInsert = new DAL.DALBangdingWeiguiJilu().Insert(WeiguiInfos);
                if (MsgInsert.Success)
                {
                    Msg.Code = 200;
                    Msg.Datas = "处理完成" ;
                    Msg.Msg = $"处理完成";
                    Msg.RecordCount = 0;
                }
                else
                {
                    Msg.Code = 400;
                    Msg.Datas = "数据处理失败";
                    Msg.Msg = $"数据处理失败";
                    Msg.RecordCount = 0;
                }
            }
            catch (System.Exception e)
            {
                Msg.Code = 404;
                Msg.Datas = "数据处理失败";
                Msg.Msg = $"数据处理失败" + e.Message;
                Msg.RecordCount = 0;
            }
            return Json<ResultMsgWeb>(Msg);
        }
  }

调用方法就是:

csharp 复制代码
var client = new RestClient("http://localhost:56727/api/BangdingWeiguiJilu/WeiguiJiluAdd");
client.Timeout = -1;
var request = new RestRequest(Method.POST);
client.UserAgent = "Apifox/1.0.0 (https://apifox.com)";
request.AddHeader("Content-Type", "application/json");
var body = @"<body data here>";
request.AddParameter("application/json", body,  ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
相关推荐
Martin-Luo3 天前
Vue3 通过json配置生成查询表单
javascript·vue.js·json
星尘库3 天前
后端json数据反序列化枚举类型不匹配的错误
json
BXCQ_xuan3 天前
软件工程实践四:MyBatis-Plus 教程(连接、分页、查询)
spring boot·mysql·json·mybatis
王维志3 天前
LiteDB详解
数据库·后端·mongodb·sqlite·c#·json·database
ID_180079054734 天前
Python采集京东店铺所有商品数据,json数据返回
json
ljh5746491194 天前
mysql 必须在逗号分隔字符串和JSON字段之间二选一,怎么选
数据库·mysql·json
小孔龙4 天前
02.Kotlin Serialization 属性序列化控制
kotlin·json
Cachel wood4 天前
信息检索、推荐系统模型排序质量指标:AP@K和MAP@K
windows·搜索引擎·json·推荐系统·搜索
tebukaopu1484 天前
json文件转excel
json·excel
小孔龙5 天前
01.Kotlin Serialization - 基础用法
kotlin·json