Hi, I am getting this error in Blazor
JsonSerializationException: Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'DTO' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.
Here is my API Code
var patientDiagnosis = await _context.PatientDiagnosis.Where(e => e.Pid == Pid).ToListAsync();
if (patientDiagnosis == null)
{
logger.LogWarning($"Record Not Found:{nameof(GetPatientDiagnosis)}-ID:{Pid}");
return NotFound();
}
return Ok(patientDiagnosis);
If I use
FirstOrDefaultAsync
API to show data in a Blazor form, but if I use
Where
then it shows the above error. But in Swagger or Postman API it is working fine.
Anybody have any idea please?
What I have tried:
I have no idea how to solve this in a Blazor app because it works in Postman and the error shows only when I use
await _context.PatientDiagnosis.Where(e => e.Pid == Pid).ToListAsync();