我有以下行动:
[Route("GetNull")]
[HttpGet]
public IActionResult GetNull()
{
object value = new { Name = "John" };
return Ok(value);
}
它返回序列化的对象:
HTTP/1.1 200 OK
Date: Tue, 12 Jun 2018 06:13:05 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Content-Length: 22
{
"name": "John"
}
如果对象像这样设置为 null:
[Route("GetNull")]
[HttpGet]
public IActionResult GetNull()
{
object value = null;
return Ok(value);
}
我希望返回 JSON 中的 null。但是,我得到这样的空内容:
HTTP/1.1 204 No Content
Date: Tue, 12 Jun 2018 06:17:37 GMT
Server: Kestrel
Content-Length: 0
我确实让控制器将 null 序列化为 json 并返回:
HTTP/1.1 200 OK
Date: Tue, 12 Jun 2018 06:13:05 GMT
Content-Type: application/json; charset=utf-8
Server: Kestrel
Content-Length: 4
null
慕运维8079593
相关分类