Asp.net 从API返回的值为空
从API调用此代码时,json值为空:Asp.net 从API返回的值为空,asp.net,.net-core,Asp.net,.net Core,从API调用此代码时,json值为空: [Route("api/[controller]")] public class ReportDesignerSetupController : ControllerBase { [HttpPost("[action]")] public object GetReportDesignerModel([FromForm] string reportUrl)
[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\"}"));
}
}
有人有任何理由认为该值为空吗
多谢各位
参考:
我正在调试与DevEXpress相关的项目
如何从邮递员/管理员那里调用web api(url)。。等您似乎正在返回数据(GET),但您的方法被标记为
[HttpPost(“[action]”)
。您可以将该方法编辑为HttpGet
并尝试吗?如果可以,请尝试使用Newtonsoft.Json。
只是在本地尝试了这段代码,效果很好
[HttpGet("test")]
public IActionResult GetReportDesignerModel([FromForm] string reportUrl)
{
return Ok(JsonConvert.DeserializeObject("{name: \"Seb\", age: 42, gender: \"M\"}"));
}
邮递员
使用失眠,与post或get一样,感谢您的建议。Adding.AddNewtonsoftJson()修复此问题。谢谢
[HttpGet("test")]
public IActionResult GetReportDesignerModel([FromForm] string reportUrl)
{
return Ok(JsonConvert.DeserializeObject("{name: \"Seb\", age: 42, gender: \"M\"}"));
}