。NET CORE 3.1 ApiController装饰器是否使用System.Text.Json返回json?

问题描述 投票:0回答:1

[我正在从.NET Core 2.2转换为.NET Core 3.1,并且我一直在使用JsonApiDotNetCore类以JSON格式将对象返回为OK:

public class ClientsController : JsonApiController<Client>
{
    [AllowAnonymous]
    [HttpGet("/Route/Page")]
    public async Task<ActionResult> TestAsync()
    {
        // Do some stuff

        return Ok(someObject);

    }
}

我正在寻找可能远离JsonApiDotNetCore的地方,并将ControllerBase与ApiController装饰器一起使用。此装饰程序是否使用System.Text.Json返回以JSON格式格式化的对象以及HTTP状态(即OK = 200)?如果不是,是否可以使用它返回对象?我要这样做,因为Microsoft已证明此新类针对高性能进行了优化。

public class ClientsController : ControllerBase
{
    [ApiController]
    [AllowAnonymous]
    [HttpGet("/Route/Page")]
    public async Task<ActionResult> TestAsync()
    {
        // Do some stuff

        return Ok(someObject);

    }
}
c# json .net-core-3.1 asp.net-apicontroller
1个回答
0
投票
您可以使用Json()返回Json;
© www.soinside.com 2019 - 2024. All rights reserved.