title: Mapping API to Object C#
body: <p>I tried to map the API to an object, but got an error:</p>
  <blockquote>
  <p><em>Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {&quot;name&quot;:&quot;value&quot;}) into type 'System.Collections.Generic.List'1[APIWebApp.Models.UserModel]' 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 '@count', line 2, position 11.'</em></p>
  </blockquote>
  <p>Here is my code:</p>
  <p>Function to run the mapping:</p>
  <pre><code>public List&lt;UserModel&gt; GetUserList()
          {
              try
              {
                  using (WebClient webClient = new WebClient())
                  {
                      webClient.Credentials = new NetworkCredential(&quot;un&quot;, &quot;pw&quot;);
                      webClient.BaseAddress = StaticItems.EndPoint;
                      var json = webClient.DownloadString(&quot;userlist?view=expand&quot;);
                      var list = JsonConvert.DeserializeObject &lt; List&lt;UserModel&gt;&gt;(json);
                      return list.ToList();
                  }
              }
              catch (WebException ex)
              {
                  throw ex;
              }
          }
  
  public static class StaticItems
  {
      public static string EndPoint = &quot;https://XXXXXX&quot;;
  }
  </code></pre>
  <p>Here is the model:</p>
  <pre><code>namespace APIWebApp.Models
  {
      public class UserModel
      {
          public int count { get; set; }
          public int start { get; set; }
          public int totalcount { get; set; }
          public object[] Messages { get; set; }
          public string ResourceName { get; set; }
          public int ReturnCode { get; set; }
          public Content[] content { get; set; }
      }
      
      public class Content
      {
          public Users user { get; set; }
      }
  
      public class Users
      {
          public string name { get; set; }
          public string age { get; set; }
          public string date { get; set; }
      }
  }
  </code></pre>
  <p>The API json:</p>
  <pre><code>{
    &quot;@count&quot;: 2,
    &quot;@start&quot;: 1,
    &quot;@totalcount&quot;: 2,
    &quot;Messages&quot;: [],
    &quot;ResourceName&quot;: &quot;user&quot;,
    &quot;ReturnCode&quot;: 0,
    &quot;content&quot;: [
      {&quot;user&quot;: {
        &quot;name&quot;: &quot;Eric&quot;,
        &quot;age&quot;: &quot;25&quot;,
        &quot;date&quot;: &quot;2021-10-23T11:18:10+00:00&quot;,
      }},
      {&quot;user&quot;: {
        &quot;name&quot;: &quot;Paul&quot;,
        &quot;age&quot;: &quot;30&quot;,
        &quot;date&quot;: &quot;2021-10-23T11:18:10+00:00&quot;,
      }}]
  }
  </code></pre>
  <p>How can I fix what's causing the error?</p>