title: Deserializing data returned single or array
body: <p>I'm using the code from <a href="http://www.codeproject.com/Tips/397574/Use-Csharp-to-get-JSON-data-from-the-web-and-map-i" rel="nofollow">this tutorial</a> and it works beautifully well at deserializing json to classes.</p>
  
  <p>While this works wonderfully with single objects, when I get an array back from the url, this doesn't handle that. I tried adjusting the code to handle an array, but I think the above code is a step above my grade at the moment.</p>
  
  <p>Can someone help me figure out what I'm doing wrong?</p>
  
  <p>Here is the <a href="https://gist.github.com/jeffpatton1971/8823781" rel="nofollow">code</a> I'm trying to get working:</p>
  
  <pre><code>public static T[] GetEdmundsContents&lt;T&gt;(string url) where T : new()
  {
      using (var client = new WebClient())
      {
          var jsonData = string.Empty;
          try
          {
              Sleep(1000);
              jsonData = client.DownloadString(url);
          }
          catch (Exception ex)
          {
              throw ex;
          }
          return !string.IsNullOrEmpty(jsonData) ? JsonConvert.DeserializeObject&lt;T[]&gt;(jsonData) : new T();
      }
  }
  
  static void Sleep(int ms)
  {
      new System.Threading.ManualResetEvent(false).WaitOne(ms);
  }
  </code></pre>
  
  <p>Here is the JSON I'm getting back from the web service (abbreviated):</p>
  
  <pre><code>[
      {
          "authorNames": [
              "Audi Press AG"
          ],
          "captionTranscript": "2013 Audi A6 3.0T Premium quattro Sedan Cargo Area",
          "type": "PHOTOS",
          "subType": "interior",
          "shotTypeAbbreviation": "CARGO",
          "photoSrcs": [
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_150.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_87.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_131.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_423.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_396.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_175.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_500.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_600.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_1600.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_400.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_2048.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_98.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_276.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_300.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_815.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_717.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_196.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_cargo_oem_1_185.jpg"
          ]
      },
      {
          "authorNames": [
              "Audi Press AG"
          ],
          "captionTranscript": "2013 Audi A6 3.0T Premium quattro Sedan Interior",
          "type": "PHOTOS",
          "subType": "interior",
          "shotTypeAbbreviation": "I",
          "photoSrcs": [
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_396.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_196.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_276.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_185.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_175.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_300.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_500.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_423.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_131.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_150.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_600.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_2048.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_87.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_717.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_1600.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_400.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_98.jpg",
              "/audi/a6/2013/oem/2013_audi_a6_sedan_30t-premium-quattro_i_oem_2_815.jpg"
          ]
      }
  ]
  </code></pre>