2、【GET】请求的API解析
创建返回对象
[Serializable] public class ResultType { public int code { get; set; } public string message { get; set; } public object result { get; set; } }
编写解析过程(HomeController.cs):
//客户端请求 HttpClient http = new HttpClient(); //请求地址 string url = "http://localhost:5833/api/Test/GetInfo"; //异步请求 Task<string> task = http.GetStringAsync(url); //获取数据解析,并发送至前台 ViewBag.ResultTyle = JsonConvert.DeserializeObject<ResultType>(task.Result); return View();