title: Converting a string into a list of objects with Newtonsoft.Json
body: <p>I receive a response from an API and need to convert it to a list of objects in my Xamarin.Forms app. The object that I am deserializing the string into is:</p>
  <pre class="lang-cs prettyprint-override"><code>public class ReturnedImg
  {
      public string Type { get; set; }
      public string Data { get; set; }
      public double MinX { get; set; }
      public double MaxX { get; set; }
      public double MinY { get; set; }
      public double MaxY { get; set; }
      public ReturnedImg(string typ, string outp, string ymax, string ymin, string xmax, string xmin)
      {
          Type = typ;
          Data = outp;
          MinX = Convert.ToDouble(xmin);
          MaxX = Convert.ToDouble(xmax);
          MinY = Convert.ToDouble(ymin);
          MaxY = Convert.ToDouble(ymax);
      }
  }
  </code></pre>
  <p>The code I attempt to use to deserialize the string into a <code>List&lt;ReturnedImg&gt;</code> object is:</p>
  <pre class="lang-cs prettyprint-override"><code>List&lt;ReturnedImg&gt; returnedImgs = JsonConvert.DeserializeObject&lt;List&lt;ReturnedImg&gt;&gt;(response);
  </code></pre>
  <p>where response is the returned string. I also tried this:</p>
  <pre class="lang-cs prettyprint-override"><code>ReturnedImg[] returnedImgs1 = JsonConvert.DeserializeObject&lt;ReturnedImg[]&gt;(response);
  </code></pre>
  <p>which also didn't work.</p>
  <p>Somehow, my API response gets double escaped somewhere between the API and the client.</p>
  <p>The string I receive from the API is:</p>
  <pre><code>&quot;\&quot;[{\\\&quot;typ\\\&quot;: \\\&quot;barcode\\\&quot;, \\\&quot;outp\\\&quot;: \\\&quot;0882658000546\\\&quot;, \\\&quot;ymax\\\&quot;: \\\&quot;0.8211805555555556\\\&quot;, \\\&quot;ymin\\\&quot;: \\\&quot;0.7199900793650794\\\&quot;, \\\&quot;xmax\\\&quot;: \\\&quot;0.8296957671957672\\\&quot;, \\\&quot;xmin\\\&quot;: \\\&quot;0.3419312169312169\\\&quot;}, {\\\&quot;typ\\\&quot;: \\\&quot;barcode\\\&quot;, \\\&quot;outp\\\&quot;: \\\&quot;A-0020-Z\\\&quot;, \\\&quot;ymax\\\&quot;: \\\&quot;0.39360119047619047\\\&quot;, \\\&quot;ymin\\\&quot;: \\\&quot;0.3881448412698413\\\&quot;, \\\&quot;xmax\\\&quot;: \\\&quot;0.7027116402116402\\\&quot;, \\\&quot;xmin\\\&quot;: \\\&quot;0.2919973544973545\\\&quot;}, {\\\&quot;typ\\\&quot;: \\\&quot;barcode\\\&quot;, \\\&quot;outp\\\&quot;: \\\&quot;A-0010-Z\\\&quot;, \\\&quot;ymax\\\&quot;: \\\&quot;0.2881944444444444\\\&quot;, \\\&quot;ymin\\\&quot;: \\\&quot;0.20833333333333334\\\&quot;, \\\&quot;xmax\\\&quot;: \\\&quot;0.6924603174603174\\\&quot;, \\\&quot;xmin\\\&quot;: \\\&quot;0.2959656084656085\\\&quot;}]\&quot;&quot;
  </code></pre>
  <p>When I tested with the string below it did serialize correctly.</p>
  <pre><code>&quot;[{\&quot;typ\&quot;: \&quot;barcode\&quot;, \&quot;outp\&quot;: \&quot;0882658000546\&quot;, \&quot;ymax\&quot;: \&quot;0.8343253968253969\&quot;, \&quot;ymin\&quot;: \&quot;0.8234126984126984\&quot;, \&quot;xmax\&quot;: \&quot;0.7235449735449735\&quot;, \&quot;xmin\&quot;: \&quot;0.22023809523809523\&quot;}, {\&quot;typ\&quot;: \&quot;barcode\&quot;, \&quot;outp\&quot;: \&quot;A-0020-Z\&quot;, \&quot;ymax\&quot;: \&quot;0.48313492063492064\&quot;, \&quot;ymin\&quot;: \&quot;0.3916170634920635\&quot;, \&quot;xmax\&quot;: \&quot;0.6084656084656085\&quot;, \&quot;xmin\&quot;: \&quot;0.17427248677248677\&quot;}, {\&quot;typ\&quot;: \&quot;barcode\&quot;, \&quot;outp\&quot;: \&quot;A-0010-Z\&quot;, \&quot;ymax\&quot;: \&quot;0.2934027777777778\&quot;, \&quot;ymin\&quot;: \&quot;0.21329365079365079\&quot;, \&quot;xmax\&quot;: \&quot;0.5949074074074074\&quot;, \&quot;xmin\&quot;: \&quot;0.18882275132275134\&quot;}]&quot;
  </code></pre>
  <p>The error message I'm getting is:</p>
  <pre><code>Newtonsoft.Json.JsonSerializationException: 'Error converting value &quot;[{&quot;typ&quot;: &quot;barcode&quot;, &quot;outp&quot;: &quot;0882658000546&quot;, &quot;ymax&quot;: &quot;0.8343253968253969&quot;, &quot;ymin&quot;: &quot;0.8234126984126984&quot;, &quot;xmax&quot;: &quot;0.7235449735449735&quot;, &quot;xmin&quot;: &quot;0.22023809523809523&quot;}, {&quot;typ&quot;: &quot;barcode&quot;, &quot;outp&quot;: &quot;A-0020-Z&quot;, &quot;ymax&quot;: &quot;0.48313492063492064&quot;, &quot;ymin&quot;: &quot;0.3916170634920635&quot;, &quot;xmax&quot;: &quot;0.6084656084656085&quot;, &quot;xmin&quot;: &quot;0.17427248677248677&quot;}, {&quot;typ&quot;: &quot;barcode&quot;, &quot;outp&quot;: &quot;A-0010-Z&quot;, &quot;ymax&quot;: &quot;0.2934027777777778&quot;, &quot;ymin&quot;: &quot;0.21329365079365079&quot;, &quot;xmax&quot;: &quot;0.5949074074074074&quot;, &quot;xmin&quot;: &quot;0.18882275132275134&quot;}]&quot; to type 'System.Collections.Generic.List`1[Label_Reader.ReturnedImg]'. Path '', line 1, position 373.'
  </code></pre>
  <p>The only difference with the other code is that the type given in the error message was <code>Label_Reader.ReturnedImg[]</code>.</p>
  <p>When I looked at the CloudWatch logs for the API, however, the method response was not double escaped; here is one of the log statements:</p>
  <pre><code>(2722b67c-8991-40d8-a7d5-e6f9dfc4477d) Method response body after transformations: &quot;[{\&quot;typ\&quot;: \&quot;barcode\&quot;, \&quot;outp\&quot;: \&quot;0882658000546\&quot;, \&quot;ymax\&quot;: \&quot;0.763640873015873\&quot;, \&quot;ymin\&quot;: \&quot;0.5935019841269841\&quot;, \&quot;xmax\&quot;: \&quot;0.8412698412698413\&quot;, \&quot;xmin\&quot;: \&quot;0.28075396825396826\&quot;}, {\&quot;typ\&quot;: \&quot;barcode\&quot;, \&quot;outp\&quot;: \&quot;A-0020-Z\&quot;, \&quot;ymax\&quot;: \&quot;0.4419642857142857\&quot;, \&quot;ymin\&quot;: \&quot;0.3506944444444444\&quot;, \&quot;xmax\&quot;: \&quot;0.728505291005291\&quot;, \&quot;xmin\&quot;: \&quot;0.25892857142857145\&quot;}, {\&quot;typ\&quot;: \&quot;barcode\&quot;, \&quot;outp\&quot;: \&quot;A-0010-Z\&quot;, \&quot;ymax\&quot;: \&quot;0.2544642857142857\&quot;, \&quot;ymin\&quot;: \&quot;0.18725198412698413\&quot;, \&quot;xmax\&quot;: \&quot;0.7106481481481481\&quot;, \&quot;xmin\&quot;: \&quot;0.29133597883597884\&quot;}]&quot;
  </code></pre>