How to check if object is JProperty or JArray

json.net

Solution

The Type property will tell you the type of the token you have.

switch(token.Type)
{
     case JTokenType.Array:
         break;
     case JTokenType.String:
         break;
}

Problem

Given the two JTokens: ``` { "Users": { "Name": "Carl" } } ``` and ``` { "Users": [ { "Name": "Carl" }, {"Name": "Peter"} ] } ``` How can I tell if Users is a JProperty or JObject/JArray? I need loop Users with ``` foreach (JObject User in myjobject["Users"]) { ... } ``` Solution It was as simple as myjobject["Users"].GetType(). However, that didn't work in the Watch debugger window, but it worked at runtime. Hrmpff.

Original source