webapi接收json字符串

前端访问webapi


<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>首页-测试</title>
</head>
<body>
    <div id="publish_article_whl_content">
  </div>
    <div>
        <input  type="text"  id="account"  />
        <input type="button" value="发送数据" id="btnSend" />
    </div>

    <script src="jquery-1.11.3.min.js"></script>
    <script>
        $("#btnSend").click(function () {
    
    
            $.ajax({
    
                 
                url: "http://localhost:8079/performance_api/Appoint/AddAppointList",
                type: "post",
				contentType:"application/x-www-form-urlencoded",
                headers: {
    
    
                 "Authorization":"Bearer I9R85qjqxQqKV/u32pW1+lEPcTTk8/TG6gvVSU6keXfJPA62bHru/XzCpVgtNVacXBL89oIFLyht3116sthTeQO5GcCnKmm+wie9fJ8v2WeXlSVzS+RfR1oUW8lOQOuC05xYrwCk5wEe4/zKQEntdKnzs5QDiY7egaH4que3YPuhesk1Mj9dXcgY0GHrVO71ogNSBu4DugUQNI9CUXSem5okLPAeMdZFps/CdI/0tRBUqnSvOKUklvh4jSu2Ny0V6kpC4FktZ9E6s6lamreCepdEvmHAT9cwqSUBh8fl1vBcgvImbG+kAVN8upjcN5Z76RaVfwJMHeF9gOR7J9fnZPwwmrvJ1xXKoAgQbWY7TXI7o5ddN0qVDz/Mtk20L9m/ZH2FXxpvKwuaxvdVEiPiurm59U6+fTF0vdvzgrkYbBJM/2TvLeNjOvLOG32tzpn/HC29MYK6ZjzjnFJUDxfjpxGZR7LGsiq3UYLRrh8jqQU="
                }, 
               data: {
    
    
                   json:"[{\"One_level\":1,\"Order_month\":\"2020-12\",\"Reward_money\":23000,\"Form_name\":\"绩效奖励\",\"Form_main_id\":\"00323ee91954439da14bb6445a1ea86d\",\"Department_name\":\"中书省\",\"Department_id\":\"5cefead5ab8e4a02a32b95b3f5b8a7e3\",\"Data_type\":2}]"
               },
                success: function (d) {
    
    
                    console.log(d);
                }
            });
        });
 
    </script>
</body>
</html>

C#后台接收

[HttpPost]
public async Task<IHttpActionResult> AddAppointList(JsonInput json)
{
    
    
	List<Appoint_form> list = null;
	if (!string.IsNullOrWhiteSpace(json.Json))
	{
    
    
		list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Appoint_form>>(json.Json);
	}
	Result result = await appoint.AddAppoint_formListAsync(list, CurrentLoginUser);
	return Json(result);
}


 /// <summary>
 /// 接收json参数
 /// </summary>
 public struct JsonInput
 {
    
    
     public string Json {
    
     get; set; }
 }

猜你喜欢

转载自blog.csdn.net/u011511086/article/details/111651235
今日推荐