title: Best approach in C# to deserialize json object that can be array or single object
body: <p>We're dealing with an json API result. Just to make our lives difficult the provider of the API returns on of the items as an array if there are multiple objects, or as a single object if there is only one.</p>
  
  <p>e.g.</p>
  
  <p>If there is only one object...</p>
  
  <pre><code>{
    propertyA: {
      first: "A",
      second: "B"
    }
  }
  </code></pre>
  
  <p>Or if there are multiple: </p>
  
  <pre><code>{
    propertyA: [
      {
        first: "A",
        second: "B"
      },
      {
        first: "A",
        second: "B"
      }
    ]
  }
  </code></pre>
  
  <p>Does anybody have a good way of dealing with this scenario?
  Ideally we'd like to serialize both to</p>
  
  <pre><code>public class ApiResult{
    public ApiItem[] PropertyA {get;set;}
  }
  </code></pre>
  
  <p>This works for the second example but of you encounter the first example you get a A first chance exception of type 'System.MissingMethodException' occurred in System.Web.Extensions.dll</p>
  
  <p>Additional information: No parameterless constructor defined for type of 'ApiItem[]'.</p>