Remove Return Header Owin Webapi

Asked

Viewed 68 times

3

A simple return query to my REST service brings the following answer:

{
  "Id": 1,
  "Descricao": "TIROLESA DE AÇO",
  "Und": "UND",
  "Fabrica": "STARROW",
  "Estoque": 9,
  "Preco": 0.39
},

But the query with more than one object starts with {"Result": [

{
"Result":   
[
  {
    ....
    ....
    ....
  } 
],
  "Id": 3,
  "Exception": null,
  "Status": 5,
  "IsCanceled": false,
  "IsCompleted": true,
  "CreationOptions": 0,
  "AsyncState": null,
  "IsFaulted": false
}

This last return brings a "header" (Result) that hinders the deserialization of my class, would have to configure the return so that the same comes only the Array JSON, without this header?

1 answer

1


I found that the return of JSON with header is related to the signature of the Webapi method that is called, for example:

If it’s a method sincrono public List<Produto> GetAllProducts() the return is:

[{
  "Id": 1,
  "Descricao": "TIROLESA DE AÇO",
  "Und": "UND",
  "Fabrica": "STARROW",
  "Estoque": 9,
  "Preco": 0.39
}]

If it’s a method assincrono public public Task<List<Produto>> GetAllProductsAsync() the return is:

{
"Result":   
[
  {
    ....
    ....
    ....
  } 
],
  "Id": 3,
  "Exception": null,
  "Status": 5,
  "IsCanceled": false,
  "IsCompleted": true,
  "CreationOptions": 0,
  "AsyncState": null,
  "IsFaulted": false
}
  • If anyone has another answer I’ll undo this as you accept.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.