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.
JArray(Object[]) Initializes a new instance of the JArray class with the specified content. JArray(JArray) Initializes a new instance of the JArray class from another JArray object.
JArray addresses = new JArray(); foreach (AddressModel address in contactAddresses) { addresses. Add(JObject. Parse( @"{""street"":""" + address. Street + @"""city"":""" + address.
it is easy, JArray myarray = new JArray(); JObject myobj = new JObject(); // myobj.
The Type property will tell you the type of the token you have.
switch(token.Type)
{
case JTokenType.Array:
break;
case JTokenType.String:
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With