首页 > 解决方案 > 从 API 返回时值为空白

问题描述

从 API 调用此代码时,json 值为空白:

    [Route("api/[controller]")]
    public class ReportDesignerSetupController : ControllerBase
    {
        [HttpPost("[action]")]
        public object GetReportDesignerModel([FromForm] string reportUrl)
        {
             return Ok(new JavaScriptSerializer().Deserialize<object>("{name: \"Seb\", age: 42, gender: \"M\"}"));
        }
    }

{
  "name": [],
  "age": [],
  "gender": []
}

有人有任何理由该值是空白吗?

非常感谢!

参考:

我正在调试一个与 DevEXpress 相关的项目。

https://community.devexpress.com/blogs/aspnet/archive/2019/12/03/reporting-for-blazor-how-to-use-document-viewer-and-report-designer-in-server-side- blazor-apps.aspx

标签: asp.net.net-core

解决方案


如果可以,请尝试使用 Newtonsoft.Json。刚刚在本地尝试了这段代码,它工作得很好

    [HttpGet("test")]
    public IActionResult GetReportDesignerModel([FromForm] string reportUrl)
    {
        return Ok(JsonConvert.DeserializeObject("{name: \"Seb\", age: 42, gender: \"M\"}"));
    }

从邮递员

从邮递员


推荐阅读