Count the number of children in my JSON file using JSON.NET with LINQ
.net, c#, json, json.net, linq
Solution
Something like this works (And I find is easiest). Mostly depends how deep your tree is going to be.
token["root"]["paramFile"].Count();
Problem
I have an xml with: ``` string xml = "<?xml .... />" + "<root>" + "<paramFile version=1.0>" + "<stuff />" + "</paramFile>" + "<paramFile version=1.0>" + "<stuff />" + "</paramFile>" + "</root>"; ``` Then I convert to JSON and parse it: ``` XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); string jsonText = JsonConvert.SerializeXmlNode(doc).Replace("\"@", "\""); JToken token = JObject.Parse(jsonText); ``` How do I get the count of the number of paramFiles in my JSON?