0

我正在尝试制作返回员工列表的 Blazor APP,但是在尝试使用 GetJsonAsync 返回列表时出现以下错误......

JsonException:'<' 是值的无效开始。路径:$ | 行号:1 | 字节位置内线:0。

控制器文件:

[ApiController]
[Route("[controller]")]
public class EmployeesController : ControllerBase
{
    private readonly IEmployeeRepository employeeRepository;
    

    public EmployeesController(IEmployeeRepository employeeRepository)
    {
        this.employeeRepository = employeeRepository;
    }

    [HttpGet]
    public async Task<ActionResult> GetEmployees()
    {

        try
        {
            return Ok(await employeeRepository.GetEmployees());
        }
        catch (Exception)
        {
            return StatusCode(StatusCodes.Status500InternalServerError
                   ,"Error retrieving data from the database");
            
        }

    }

服务类:

    public async Task<IEnumerable<Employee>> GetEmployees()
    {
        return await httpClient.GetJsonAsync<Employee[]>("employees");
    }

Blazor 基类:

 public class EmployeeListBase : ComponentBase
{

    [Inject]
    IEmployeeService EmployeeService { get; set; }

    

    public IEnumerable<Employee> Employees { get; set; }

    protected override async Task OnInitializedAsync()
    {
        Employees = (await EmployeeService.GetEmployees()).ToList();
    }


}
4

0 回答 0