title: create c# object from json array
body: <p>I am receiving an error when trying to convert my json array into an object.</p>
  
  <p>I have a Json array with multiple layers like this : </p>
  
  <pre><code>    {  
     "error":"0",
     "result":{  
        "activities":{  
           "1":{  
              "activity_id":"15803",
              "activity_id_name":"Ashtanga vinyasa",
              "schedule":{  
                 "1":{  
                    "available":"30",
                    "start":"09:00:00"
                 }
              }
           },
           "2":{  
              "activity_id":"15804",
              "activity_id_name":"Yin/Yang",
              "schedule":{  
                 "1":{  
                    "available":"30",
                    "start":"10:30:00"
                 }
              }
           },
           "3":{  
              "activity_id":"15805",
              "activity_id_name":"Stress relief",
              "schedule":{  
                 "1":{  
                    "available":"30",
                    "start":"20:00:00"
                 }
              }
           }
        },
        "json_code":"2"
     },
     "id":null
  }
  </code></pre>
  
  <p>From this i created an object that looks like this : </p>
  
  <pre><code>namespace LesRooster.Models
  {
      public class JsonGroup
      {
          public string Error { get; set; }
          public List&lt;Results&gt; Result { get; set; }
          public string Id { get; set; }
  
      }
  
      public class Results
      {
          public Activities YogaActivities { get; set; }
          public int JsonCode { get; set; } 
      }
  
      public class Activities
      {
          public int ActivityId { get; set; }
          public string ActivityIdName { get; set; }
          public Schedule LesSchedule { get; set; }
      }
  
      public class Schedule
      {
          public int Available { get; set; }
          public DateTime Start { get; set; }
      }
  
  }
  </code></pre>
  
  <p>When I try to add the array to the object with the following line : </p>
  
  <pre><code>JsonGroup jgroup = JsonConvert.DeserializeObject&lt;JsonGroup&gt;(JsonArrayCode);
  </code></pre>
  
  <p>I am receiving the following error : </p>
  
  <blockquote>
    <p>Cannot deserialize the current JSON object (e.g. {"name":"value"})
    into type
    'System.Collections.Generic.List`1[LesRooster.Models.Results]' because
    the type requires a JSON array (e.g. [1,2,3]) to deserialize
    correctly.</p>
  </blockquote>
  
  <p>Is there any way to resolve this? I would like to keep it as an object since it is easy to pass on in the view in my mvc5 application.</p>
  
  <p>I have tried googling this but all solutions I have found are for single dimension json arrays.</p>
  
  <p>The documentation of the API I request the json array from looks as follows : </p>
  
  <pre><code>json_code   integer 
  Constant value: 2
  activities  hash    
      {
      index : {
          activity_id: integer
          activity_id_name: string
          schedule: hash
          {
              index : {
                  available: integer
                  start: time
                  }
              }
          }
  }
  </code></pre>