2
I’m having trouble consuming a return json and convert it into object to then write in the database, my variables always return "null", I have tried several forms and always stay barred in this return. Follows part of the code:
1) Content of Json:
{  
  "list":[  
    {  
      "Pedido":"1234",
      "Data":"2018-05-21",
      "Cliente":"Jose Teste",
      "Itens":[  
        {  
          "Codigo":"1",
          "Quantidade":1,
          "ItemNome":"Tomada trifasica Elgin",
          "Preco":25.50
        }
      ],
      "Total":25.50,
      "FormaDePagamento":"cheque",
    }
  ]
}
2) Model class C#:
namespace ApiTeste.Models
{
    public class Pedidos
    {
        public Pedido[] list { get; set; }
        //public List<Pedido> pedido { get; set; }
    }
    public class Pedido
    {
        public string NumPedido { get; set; }
        public string Data { get; set; }
        public string Cliente { get; set; }
        public Iten[] Itens { get; set; }
        public float Total { get; set; }
        public string FormaDePagamento { get; set; }
    }
    public class Iten
    {
        public string Codigo { get; set; }
        public int Quantidade { get; set; }
        public string ItemNome { get; set; }
        public float Preco { get; set; }
    }
}
3) Part of the method that returns Json to direct to the object:
using (HttpWebResponse retornoServJson = (HttpWebResponse)requisicaoWeb.GetResponse())
{
    using (Stream retornoServJson = retornoJson.GetResponseStream())
    {                   
        using (StreamReader retornoReaderJson = new StreamReader(retornoServJson))
        {
            var response = retornoReader.ReadToEnd();
            Pedido pedido = new JavaScriptSerializer().Deserialize<Pedido>(response);  //aqui o objeto retorna null
            string teste = pedido.NumPedido; //aqui o objeto retorna null
            string teste2 = pedido.Data; //aqui o objeto retorna null
        }
    }
}
Elivelton, thanks for posting, but keeps returning "null", when I run in debug mode I see that Steps do not pass the class "Request", I believe that my implementation is wrong before this step, I will review. If you have a tip thank you. Hugs.
– Cleber Pessoal