title: Deserializing HTTP response
body: <p>I am unable to deserialize my HTTP response. Could anybody tell me how exactly to do this?</p>
  
  <p>I initially used List to deserialize the response, but it threw me a null exception since the response is a json array. </p>
  
  <pre><code>int count=0;
  var obj = JsonConvert.DeserializeObject&lt;List&lt;getAllDevices.Class1&gt;&gt;(receivedData);
  Console.WriteLine("\n\nReceived Data________________\n" + receivedData + "\n");
   foreach (var item in obj)
       {
          if(item.name=="device")
          Console.WriteLine(item.name);
          foreach(var item2 in item)
             {
               if(item2.action_def.id=="increase")
                  count++;
             }
        }  
  </code></pre>
  
  <p>My getAllDevices class has the following:</p>
  
  <pre><code>class getAllDevices
  {
      public class Rootobject
      {
          public Class1[] Property1 { get; set; }
      }
  
      //public Class1[] Property1 { get; set; }
      public class Class1
      {
          public string _id { get; set; }
          public Discovery discovery { get; set; }
          public bool is_authorized { get; set; }
          public bool is_available { get; set; }
          public bool is_enabled { get; set; }
          public bool is_visible { get; set; }
          public bool deleted { get; set; }
          public string name { get; set; }
          public string vendor_name { get; set; }
          public string type { get; set; }
          public Hardware_Id[] hardware_id { get; set; }
          public DateTime created { get; set; }
          public string user_id { get; set; }
          public Datastream[] datastreams { get; set; }
          public Trigger[] triggers { get; set; }
          public Condition[] conditions { get; set; }
          public Action[] actions { get; set; }
          public DateTime last_updated { get; set; }
          public DateTime authorization_updated_on { get; set; }
          public Credentials credentials { get; set; }
          public object[] preferences { get; set; }
          public string[] parent_ids { get; set; }
          public string classification { get; set; }
          public object[] states { get; set; }
          public string subtype { get; set; }
          public string description { get; set; }
          public Metadata metadata { get; set; }
      }
      public class Value
      {
          public bool visible { get; set; }
          public string id { get; set; }
          public string label { get; set; }
          public string datastream_key { get; set; }
      }
  
      public class Action
      {
          public string _id { get; set; }
          public object last_executed { get; set; }
          public Action_Def action_def { get; set; }
          public Param2[] _params { get; set; }
      }
      public class Discovery
      {
          public bool fake_discovery { get; set; }
      }
  
      public class Action_Def
      {
          public bool hidden { get; set; }
          public bool show_as_manual_action { get; set; }
          public string _id { get; set; }
          public string id { get; set; }
          public string name { get; set; }
          public int order { get; set; }
          public bool requires_push_message { get; set; }
          public string simple_name { get; set; }
      }
  
      public class Param2
      {
          public Ui2 ui { get; set; }
          public Value1[] values { get; set; }
          public string id { get; set; }
          public string label { get; set; }
          public string type { get; set; }
          public object default_value { get; set; }
          public int limit_lower { get; set; }
          public int limit_upper { get; set; }
          public string values_datastream_key { get; set; }
          public string values_datastream_type_id { get; set; }
          public string substitution_type { get; set; }
      }
  
      public class Ui2
      {
          public object presentation_value { get; set; }
          public string _interface { get; set; }
          public int step_size { get; set; }
          public int step_hold_size { get; set; }
      }
  
      public class Value1
      {
          public bool visible { get; set; }
          public string id { get; set; }
          public string label { get; set; }
          public string datastream_key { get; set; }
          public string _id { get; set; }
      }
      public class Credentials
      {
          public string token { get; set; }
          public string refresh_token { get; set; }
          public int expires_in { get; set; }
          public bool connected { get; set; }
          public long last_updated { get; set; }
      }
  
      public class Metadata
      {
          public string modelNumber { get; set; }
          public string thermostatRev { get; set; }
          public string runtimeRev { get; set; }
          public string type { get; set; }
          public string thermostat_id { get; set; }
          public string id { get; set; }
          public string code { get; set; }
          public int house_id { get; set; }
          public int dev_cat { get; set; }
          public int sub_cat { get; set; }
      }
  
      public class Hardware_Id
      {
          public string type { get; set; }
          public object id { get; set; }
      }
  
      public class Datastream
      {
          public string _id { get; set; }
          public Current_Value current_value { get; set; }
          public DateTime last_updated { get; set; }
          public Datastream_Def datastream_def { get; set; }
      }
  
      public class Current_Value
      {
          public object value { get; set; }
          public Away away { get; set; }
          public Home home { get; set; }
          public Sleep sleep { get; set; }
      }
  
      public class Away
      {
          public string name { get; set; }
          public string climateRef { get; set; }
      }
  
      public class Home
      {
          public string name { get; set; }
          public string climateRef { get; set; }
      }
  
      public class Sleep
      {
          public string name { get; set; }
          public string climateRef { get; set; }
      }
  
      public class Datastream_Def
      {
          public bool log_update { get; set; }
          public bool log_duplicate_update { get; set; }
          public string _id { get; set; }
          public string id { get; set; }
          public string name { get; set; }
      }
  
      public class Trigger
      {
          public string _id { get; set; }
          public object last_triggered { get; set; }
          public string datastream_id { get; set; }
          public Trigger_Def trigger_def { get; set; }
          public Param[] _params { get; set; }
      }
  
      public class Trigger_Def
      {
          public bool repeatedly_trigger { get; set; }
          public bool hidden { get; set; }
          public string _id { get; set; }
          public string datastream_id { get; set; }
          public string default_condition { get; set; }
          public string default_value { get; set; }
          public string id { get; set; }
          public string name { get; set; }
          public int order { get; set; }
          public string simple_name { get; set; }
      }
  
      public class Param
      {
          public object[] values { get; set; }
          public string id { get; set; }
          public string label { get; set; }
          public string type { get; set; }
          public string substitution_type { get; set; }
          public string default_condition { get; set; }
          public object default_value { get; set; }
          public string values_datastream_key { get; set; }
          public Ui ui { get; set; }
          public int limit_lower { get; set; }
          public int limit_upper { get; set; }
      }
  
      public class Ui
      {
          public string _interface { get; set; }
          public int step_size { get; set; }
          public int step_hold_size { get; set; }
      }
  
      public class Condition
      {
          public string _id { get; set; }
          public object last_state_change { get; set; }
          public string datastream_id { get; set; }
          public Condition_Def condition_def { get; set; }
          public Param1[] _params { get; set; }
      }
  
      public class Condition_Def
      {
          public bool hidden { get; set; }
          public string _id { get; set; }
          public string datastream_id { get; set; }
          public string default_condition { get; set; }
          public string default_value { get; set; }
          public string id { get; set; }
          public string name { get; set; }
          public int order { get; set; }
          public string simple_name { get; set; }
      }
  
      public class Param1
      {
          public Value[] values { get; set; }
          public string id { get; set; }
          public string label { get; set; }
          public string type { get; set; }
          public string substitution_type { get; set; }
          public string default_condition { get; set; }
          public object default_value { get; set; }
          public string values_datastream_key { get; set; }
          public Ui1 ui { get; set; }
          public int limit_lower { get; set; }
          public int limit_upper { get; set; }
      }
  
      public class Ui1
      {
          public string _interface { get; set; }
          public int step_size { get; set; }
          public int step_hold_size { get; set; }
      }
      }
  }
  </code></pre>
  
  <p>When I use </p>
  
  <pre><code> var obj = JsonConvert.DeserializeObject&lt;getAllDevices.Rootobject&gt;(receivedData);
      CrestronConsole.PrintLine("\n\nReceived Data________________\n" + receivedData + "\n");
      foreach (var item in obj.Property1)
      {
      }
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code> Cannot deserialize JSON array into type 
      'yonomi_one_test_one.getAllDevices+Rootobject'.-----   at 
      Newtonsoft.Json.Serialization.JsonSerializerInternalReader.EnsureArrayContrac (Type objectType, JsonContract contract) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String reference)
  </code></pre>
  
  <p>My JSON response looks like this. I used JSON to c# converter tool online to get my getAllDevices class. </p>
  
  <pre><code>[ {
      "_id": "5cf528969bcb5a0069cb6039",
      "discovery": {
          "fake_discovery": false
      },
      "is_authorized": true,
      "name": "Plug In Module",
      "conditions": [],
      "actions": [
          {
              "_id": "5cf528969bcb5a0069cb603c",
              "last_executed": "2019-06-13T14:31:56.302Z",
              "action_def": {
                  "hidden": false,
                  "show_as_manual_action": true,
                  "_id": "5a317841ac537b0013a2a7cc",
                  "id": "turn_on",
                  "name": "Turn On to {level}%",
                  "order": 0,
                  "requires_push_message": false,
                  "simple_name": "Turn On to Brightness%"
              },
  
          {
              "_id": "5cf528969bcb5a0069cb603e",
              "last_executed": null,
              "action_def": {
                  "hidden": false,
                  "show_as_manual_action": true,
                  "_id": "5a317899ac537b0013a2a7ce",
                  "id": "set_brightness",
                  "name": "Set Brightness to {level}%",
                  "order": 3,
                  "requires_push_message": false,
                  "simple_name": "Set Brightness to Level%"
              },
              "params": [
                  {
                      "ui": {
                          "interface": "slider",
                          "step_size": 5,
                          "step_hold_size": 10,
                          "presentation_value": 10
                      },
                      "values": [],
                      "id": "level",
                      "label": "Percent",
                      "type": "Number",
                      "default_value": 10,
                      "limit_lower": 0,
                      "limit_upper": 100
                  }
              ]
          }
      ],
      "last_updated": "2019-06-13T14:32:05.413Z",
      "parent_ids": [
          "5cf03e05aa4d770038167dfd"
      ],
      "classification": "device",
      "states": []
  }
  ]
  </code></pre>