title: Json response to C# Object
body: <p>I am trying to convert Json Response to C# object. My code is as below.</p>
  
  <p>$ HttpResponseMessage response = client.GetAsync(TARGETURL).Result;</p>
  
  <pre><code>        HttpContent content = response.Content;
  
          // ... Check Status Code                                
          Console.WriteLine("Response StatusCode: " + (int)response.StatusCode);
  
          // ... Read the string.
          string result = content.ReadAsStringAsync().Result;
  
          Environment myJsonResponse = Newtonsoft.Json.JsonConvert.DeserializeObject&lt;Environment&gt;(result);
          Console.Write(myJsonResponse.id);
  </code></pre>
  
  <p>My Json Object Class is:</p>
  
  <pre><code>public class Environment
  {
  public string id { get; set; }
  public string url { get; set; }
  public string name { get; set; }
  public string error { get; set; }
  public int container_hosts_count { get; set; }
  }
  </code></pre>
  
  <p>Result string is:</p>
  
  <pre><code>"[{\"id\":\"23745576\",\"url\":\"https://cloud.mycloud.com/configurations/23745576\",\"name\":\"mycloud Code Screen - Andy Pande\",\"error\":\"\",\"container_hosts_count\":0}]"
  </code></pre>
  
  <p>I am getting an error as:</p>
  
  <pre><code>Newtonsoft.Json.JsonSerializationException occurred
    HResult=0x80131500
    Message=Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'Environment' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
  To 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&lt;T&gt; 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.
  Path '', line 1, position 1.
  </code></pre>