title: Deserialize json array using RestSharp and JSON.Net in C# ASP.NET
body: <p>I am having an issue I have been researching and can not seem to figure out.  I am trying to deserialize Json return from a restsharp call to an api.  It worked great on my first one where there was not an array involved.  Now that I am trying to do it on a string with an array in it I am having issues.  If anybody could help me figure this out it would be greatly appreciated, thank you in advance.</p>
  
  <p>So I am trying to get Roles to be stored to my Model, but it fails because it is an array:</p>
  
  <p>Here is my method:</p>
  
  <pre><code>var request = new RestRequest("api/user/{id}", Method.GET);
  request.AddUrlSegment("id", id);
  var response = client.Execute(request) as RestResponse;
  var d = JsonConvert.DeserializeObject&lt;List&lt;MyModel&gt;&gt;(response.Content);
  </code></pre>
  
  <p>The error I am getting is on the above line at <code>var d = ...</code>. It says:</p>
  
  <pre class="lang-none prettyprint-override"><code>Cannot implicitly convert type
  'System.Collections.Generic.List&lt;Models.MyModel&gt;' to 'Models.MyModel'
  </code></pre>
  
  <p>The response for <code>var response</code> is (trying to get Roles stored in <code>d</code> to store in model):</p>
  
  <pre><code>"{\"Id\":22,\"FirstName\":\"Shawn\",\"LastName\":\"John\",\"Roles\":[\"User\"]}"
  </code></pre>
  
  <p>My MyModel looks like so:</p>
  
  <pre><code>public class MyModel
  {
      public string Id { get; set; }
      public string Roles { get; set; }
  }
  </code></pre>
  
  <h3>Updated code</h3>
  
  <p>Getting this error now on the same line:</p>
  
  <pre class="lang-none prettyprint-override"><code>Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type
  'System.Collections.Generic.List`1[Models.MyModel]' 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&lt;T&gt;) 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.
  </code></pre>
  
  <p>Changed model to be :</p>
  
  <pre><code>public List&lt;MyModel&gt; Roles { get; set; }
  </code></pre>
  
  <p>and controller variable to :</p>
  
  <pre><code>List&lt;MyModel&gt; deSerialize2 = 
      JsonConvert.DeserializeObject&lt;List&lt;MyModel&gt;&gt;(response.Content);
  </code></pre>