title: How to store API result set for different response types using C#.Net
body: <p>I am trying to call two API's and store their response.
  Below is the API response type:</p>
  
  <p>API1 response:</p>
  
  <pre><code>{
    "Name": "Apple",
    "Expiry": "2008-12-28T00:00:00",
   "Price": 3.99,
   "Sizes": [
   "Small",
   "Medium",
   "Large"
    ]
  }
  </code></pre>
  
  <p>API2 Response:</p>
  
  <pre><code>["Name=xyz, Id=1, Version=1","Name=abc, Id=1, Version=2","Name=hgf, Id=1, Version=3","Name=utgds, Id=1, Version=4","Name=kfgf, Id=2, Version=1"]
  </code></pre>
  
  <p>below is the code to call an API and get the result set.</p>
  
  <pre><code>var jsonObj = Get&lt;SomeClass&gt;("API_URL1");
  var jsonObj2 = Get&lt;Test&gt;("API_URL2");
  
   public T Get&lt;T&gt;(string requestUri)
          {
              T response = default(T);
              using (var handler = new HttpClientHandler { Credentials = CredentialCache.DefaultNetworkCredentials })
              {
                  using (var httpClient = CreateNewRequest(handler))
                  {
                      var httpTask = httpClient.GetAsync(requestUri);
                      var response = task.Result;
                      response.EnsureSuccessStatusCode();
                      if (response.IsSuccessStatusCode)
                      {
                          var result = response.Content.ReadAsStringAsync().Result;
                          var res = JsonConvert.DeserializeObject&lt;T&gt;(result);
  
                      }
                  }
              }
              return res;
          }
  
   private HttpClient CreateNewRequest(HttpClientHandler handler)
      {
          HttpClient client = new HttpClient(handler);
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
          return client;
      }
  
  public class Test
  {
      public string Name { get; set; }
      public int Id { get; set; }
      public int Version { get; set; }
  
  
  }
  </code></pre>
  
  <p>Similarly i have created a class to hold the API1 response.
  I am able to store API1 Response however while storing API2 response i am getting this error message.</p>
  
  <blockquote>
    <p>Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 
    because the type requires a JSON object (e.g. {"name":"value"}) to
    deserialize correctly. To fix this error either change the JSON to a
    JSON object (e.g. {"name":"value"}) or change the deserialized type to
    an array or a type that implements a collection interface..</p>
  </blockquote>
  
  <p>any idea/hints on this?</p>
  
  <p>Thanks!</p>