-1

Help me with my problem i try get data from web API for method post, but always show null.

    public class ShippingQuantity
    {
      public string QuantityLoad { get; set; }
      public string QuantityLoaded { get; set; }
      public string QuantityPendingLoad { get; set; }
      public string ElementInfo { get; set; }
      public Guid kElement { get; set; }
      public string LineNumber { get; set; }
   }


   public class ShippingQuantityData
   {
      public List<ShippingQuantity> shippingData { get; set; }
      public string message { get; set; }
   }

and it its my code

         using (var client = new HttpClient())
         {
            client.BaseAddress = new Uri(Baseurl);
            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage Res = await client.PostAsync(urlService, formContent);
            if (Res.IsSuccessStatusCode)
            {
               var Response = Res.Content.ReadAsStringAsync().Result;
               data = JsonConvert.DeserializeObject<ShippingQuantityData>(Response);
            }

when execute for mode debug the variable Response show it

 "{
  \"data\": [
    {
      \"QuantityLoad\": \"5\",
      \"QuantityLoaded\": \"1\",
      \"QuantityPendingLoad\": \"4\",
      \"ElementInfo\": \"2147-PIZZA 6 UNIDADES\",
      \"kElement\": \"8fa2ec91-2b20-415c-a65d-11c13d6725fd\",
      \"LineNumber\": \"1\"
    }
  ],
  \"Message\": \"\"
}"

thanks

G K
  • 2,481
  • 4
  • 29
  • 45
Martin Chinome
  • 431
  • 5
  • 17

1 Answers1

0

Your json is List<T> and you tried to deserialize the list to an object, try deserialize to List<T>.

narekye
  • 114
  • 3
  • But ShippingQuantityData is a single object which contains a List and a string property (Message). So I think that won't be any problem with the serialization. – G K Oct 09 '17 at 16:56
  • I already mean this. – narekye Oct 09 '17 at 16:57
  • 1
    Thanks for you comments, my problem was resolve , set this decorator to all propertys and ii working [JsonProperty("NamePropertyObjectJson")] – Martin Chinome Oct 09 '17 at 17:17