title: How to Deserializing JSON Object Array with Xamarin forms
body: <p>I am trying to convert this json array to show data in the list view. But i getting this error when i parsing this.</p>
  
  <p>Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[Apps.Models.RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
      To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
  Path 'id', line 1, position 6.</p>
  
  <p><strong>JSON Files look like:</strong></p>
  
  <pre><code>{
      "id": 2,
      "parent_id": 1,
      "name": "Default Category",
      "is_active": true,
      "position": 1,
      "level": 1,
      "product_count": 4503,
      "children_data": [
          {
              "id": 848,
              "parent_id": 2,
              "name": "GROCERIES",
              "is_active": true,
              "position": 0,
              "level": 2,
              "product_count": 198,
              "children_data": [
                  {
                      "id": 849,
                      "parent_id": 848,
                      "name": "SUGAR",
                      "is_active": true,
                      "position": 0,
                      "level": 3,
                      "product_count": 13,
                      "children_data": [
                          {
                              "id": 850,
                              "parent_id": 849,
                              "name": "RING",
                              "is_active": true,
                              "position": 0,
                              "level": 4,
                              "product_count": 3,
                              "children_data": []
                          }
                      ]
                  },
                  {
                      "id": 851,
                      "parent_id": 848,
                      "name": "RICE",
                      "is_active": true,
                      "position": 0,
                      "level": 3,
                      "product_count": 47,
                      "children_data": [
                          {
                              "id": 852,
                              "parent_id": 851,
                              "name": "RING",
                              "is_active": true,
                              "position": 0,
                              "level": 4,
                              "product_count": 1,
                              "children_data": []
                          }
                      ]
                  }
              ]
          },
      {
          "id": 2017,
          "parent_id": 2,
          "name": "Food Basket",
          "is_active": true,
          "position": 2,
          "level": 2,
          "product_count": 19,
          "children_data": []
      }
  ]}
  </code></pre>
  
  <p><strong>My Model Class is:</strong>
   I create a model class like this.</p>
  
  <pre><code>public class ChildrenData2
  {
       public string id { get; set; }
       public string parent_id { get; set; }
       public string name { get; set; }
       public string is_active { get; set; }
       public string position { get; set; }
       public string level { get; set; }
       public string product_count { get; set; }
       public List children_data { get; set; }
  }
  
  public class ChildrenData
  {
      public ChildrenData2 children_data { get; set; }
  }
  
  public class RootObject
  {
      public List&lt;ChildrenData&gt; children_data { get; set; }
  }
  </code></pre>
  
  <p><strong>JSON Deserialize Code:</strong>
  I am trying this code to parse the json array.</p>
  
  <pre><code>var client = new System.Net.Http.HttpClient();
  client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue(
                      Constants.AccessName, Constants.AccessToken);
  
  var json = await client.GetAsync(Constants.BaseApiAddress + "V1/categories");
  string contactsJson = await json.Content.ReadAsStringAsync();
  
  if (contactsJson != "")
  {
         //Converting JSON Array Objects into generic list  
         Newtempdata = JsonConvert.DeserializeObject&lt;List&lt;RootObject&gt;&gt;(contactsJson);
  }
  </code></pre>