title: C#, JSON Parsing, dynamic variable. How to check type?
body: <p>I'm parsing JSON texts. Sometimes I get <code>Array</code> and sometimes <code>Object</code> types in the text. I tried to check the type as follows:</p>
  
  <pre><code>dynamic obj = JsonConvert.DeserializeObject(text);  //json text
  if (obj is Array)
  {  
      Console.WriteLine("ARRAY!");
  }
  else if (obj is Object)
  {
      Console.WriteLine("OBJECT!");
  }
  </code></pre>
  
  <p>I checked the types while debugging. <code>obj</code> had <code>Type</code> property as <code>Object</code> when parsing objects and <code>Array</code> when parsing arrays. However the console output was <code>OBJECT!</code> for both situations. Obviously I'm checking the type in a wrong manner. What is the correct way to check the type?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>JSON contents:</p>
  
  <p><code>[ {"ticket":"asd", ...}, {..} ]</code> or <code>{ "ASD":{...}, "SDF":{...} }</code></p>
  
  <p>In both situations I get the output as <code>OBJECT!</code>.</p>
  
  <p><strong>EDIT#2</strong></p>
  
  <p>I changed the typechecking order as @Houssem suggested. Still the same output. Therefore I changed the OP as well. My code is like this right now, and I still get the same result.</p>