I can POST this information:
{
"Nritem": 1,
"Cdprevenda": 3,
"Cdproduto": 7,
"Decomplitem": "",
"Descricao": "Depilação",
"Dtcadastro": "2015-11-27T13:53:35.120Z",
"Flsituacao": 1,
"Md5": "",
"Qtproduto": 18,
"Totalizador": "01T1700",
"Unidade": "UN",
"Vltabela": 50,
"Vlunitario": 50,
}
But if you put between []
this message appears:
"itemprevenda":[
"Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'PreVendaWebAPI.Models.Itemprevenda' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo 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.\r\nPath '', line 1, position 1."]
API that does POST:
// POST: api/Itemprevendas
[ResponseType(typeof(Itemprevenda))]
public async Task<IHttpActionResult> PostItemprevenda(Itemprevenda itemprevenda)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// Implementar o Cditemprevenda e o Nritem automaticamente
decimal cd = await GetMaiorCod();
decimal nr = await GetMaiorNr(itemprevenda.Cdprevenda);
itemprevenda.Cditemprevenda = cd;
itemprevenda.Nritem = nr;
// *******************************************************
db.Itemprevenda.Add(itemprevenda);
try
{
await db.SaveChangesAsync();
}
catch (DbUpdateException)
{
if (ItemprevendaExists(itemprevenda.Cditemprevenda))
{
return Conflict();
}
else
{
throw;
}
}
return CreatedAtRoute("DefaultApi", new { id = itemprevenda.Cditemprevenda }, itemprevenda);
}
Pre-order item:
public partial class Itemprevenda
{
public decimal Cditemprevenda { get; set; }
public decimal Cdprevenda { get; set; }
public decimal Cdproduto { get; set; }
public decimal Nritem { get; set; }
public decimal Qtproduto { get; set; }
public decimal Vltabela { get; set; }
public decimal Vldesconto { get; set; }
public decimal Vlacrescimo { get; set; }
public decimal Vlunitario { get; set; }
public int Flsituacao { get; set; }
public System.DateTime Dtcadastro { get; set; }
public string Descricao { get; set; }
public string Unidade { get; set; }
public string Totalizador { get; set; }
public byte[] Md5 { get; set; }
public string Decomplitem { get; set; }
public decimal Cdvendedor { get; set; }
public decimal Vltotal { get; set; }
}
How do I deserialize this JSON?