I've created a WEB API project with EMPTY template. I would like the GetOne () method to return a json object but it is returning an json array. Why?
I would like it to return:
{"Id": 1, "Nome":"Jhon"}
But it's returning:
[{"Id": 1, "Nome":"Jhon"}]
My controller looks like this:
public class PessoaController : ApiController
{
private DataModel db = new DataModel();
public IHttpActionResult GetOne(int id) => Ok(GetPessoa(id));
private IQueryable GetPessoa(int id)
{
var pessoa = (from f in db.Pessoas
where f.Id == id
select new
{
Id = f.Id,
Nome = f.Nome
});
return pessoa;
}
}
}
WebApiConfig.cs looks like this:
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);