【问题标题】:Result from API Post request not showing in viewAPI Post 请求的结果未显示在视图中
【发布时间】:2021-09-11 13:19:13
【问题描述】:

我想知道是否有人可以就 API 发布请求的结果为什么没有显示在我的视图中提出建议。

      if (token != null)
        {
            client.SetBearerToken(token.AccessToken);
            //ResultModel resultModel = new ResultModel();
            Result result = new Result();
            
            var response = await client.PostAsJsonAsync(address, bodyJson, null);
            if (response.IsSuccessStatusCode)
            {
               string apiResponse = await response.Content.ReadAsStringAsync();
                //resultModel = JsonConvert.DeserializeObject<ResultModel>(apiResponse);
                result = JsonConvert.DeserializeObject<Result>(apiResponse);
            }
            return View(result);
        }
        return View();

我很难弄清楚为什么没有显示结果,我使用 PASTE 特殊的粘贴 JSON 作为类,并删除了我不想显示的那些。

我尝试使用 for each 循环显示结果,因为显示中有 17 个结果。

public class Result
{
    public class Rootobject
    {
        public string SearchGuid { get; set; }
        public Button[] Buttons { get; set; }
        public string CaseRef { get; set; }

    }

    public class Button
    {
        public string DisplayName { get; set; }
    }
}

【问题讨论】:

  • 结果类没有属性……结果总是无效的……

标签: c# asp.net asp.net-mvc


【解决方案1】:

你必须修复类

public class Result
{
    public Rootobject Rootobject {get; set;}
    public Button Button {get; set;}
 
}
 public class Rootobject
    {
        public string SearchGuid { get; set; }
        public Button[] Buttons { get; set; }
        public string CaseRef { get; set; }

    }
   public class Button
    {
        public string DisplayName { get; set; }
    }

【讨论】:

    猜你喜欢
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 2021-08-05
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 2018-03-08
    相关资源
    最近更新 更多