title: Determine if Json results is object or array
body: <p>I am using .net web api to get json and return it to the front end for angular. The json can be either an object or an array. My code currently only works for the array not the object. I need to find a way to tryparse or determine if the contents are an object or array.</p>
  
  <p>Here is my code </p>
  
  <pre><code>    public HttpResponseMessage Get(string id)
      {
          string singleFilePath = String.Format("{0}/../Data/phones/{1}.json", AssemblyDirectory, id);
          List&lt;Phone&gt; phones = new List&lt;Phone&gt;();
          Phone phone = new Phone();
          JsonSerializer serailizer = new JsonSerializer();
  
          using (StreamReader json = File.OpenText(singleFilePath))
          {
              using (JsonTextReader reader = new JsonTextReader(json))
              {
                  //if array do this
                  phones = serailizer.Deserialize&lt;List&lt;Phone&gt;&gt;(reader);
                  //if object do this
                  phone = serailizer.Deserialize&lt;Phone&gt;(reader);
              }
          }
  
          HttpResponseMessage response = Request.CreateResponse&lt;List&lt;Phone&gt;&gt;(HttpStatusCode.OK, phones);
  
          return response;
      }
  </code></pre>
  
  <p>The above may not be best way of doing this. Its just where I am now.</p>