How can I get the length of a JSON Array I get using json.net in C#? After sending a SOAP call I get a JSON string as answer, I use json.net to parse it.
Example of
You can cast the object to a JArray and then use the Count property, like so:
JArray items = (JArray)test["JSONObject"];
int length = items.Count;
You can then loop the items as follows:
for (int i = 0; i < items.Count; i++)
{
var item = (JObject)items[i];
//do something with item
}
According to Onno (OP), you can also use the following:
int length = test["JSONObject"].Count();
However, I have not personally confirmed that this will work