title: Json Deserialize a webclient response C#
body: <p>I am new in C# and I know there are hundreds of examples on the google for Json deserialization. I tried many but could not understand how C# works for deserialization.</p>
  
  <pre><code>using (var client = new WebClient())
  {
      client.Headers.Add("Content-Type", "text/json");                
      result = client.UploadString(url, "POST", json);
  }
  </code></pre>
  
  <p>result looks like this:</p>
  
  <pre><code>{"Products":[{"ProductId":259959,"StockCount":83},{"ProductId":420124,"StockCount":158}]}
  </code></pre>
  
  <p>First I created a class:</p>
  
  <pre><code>public class ProductDetails
  {
      public string ProductId { get; set; }
      public string StockCount { get; set; }                        
  }
  </code></pre>
  
  <p>Then I tried to deserialize using this statement but couldn't understand.</p>
  
  <pre><code>var jsonresult = JsonConvert.DeserializeObject&lt;ProductDetails&gt;(result);
  Debug.WriteLine(jsonresult.ProductId);
  </code></pre>
  
  <p>The above worked fine in visual basic with the following code but how to do this similar in C#</p>
  
  <pre><code>Dim Json As Object
  Set Json = JsonConverter.ParseJson(xmlHttp.responseText)
  
  For Each Product In Json("Products")
      Debug.Print = Product("ProductId")
      Debug.Print = Product("StockCount")
  Next Product
  </code></pre>