using System.Collections.Generic; using Newtonsoft.Json.Linq; namespace analyzeJSON { public class AnalyzeStructure { private Dictionary nodes = new Dictionary(); private Dictionary leafs = new Dictionary(); public AnalyzeStructure() { } public void AnalyzeToken(JToken token) { if (token.Type == JTokenType.Object || token.Type == JTokenType.Array) return; var tokenName = AnalyzeJSON.GetNameFromPath(token.Path); if (token.HasValues) { if (token.First.Equals(token.Last) && token.First.Type != JTokenType.Array && token.First.Type != JTokenType.Property && token.First.Type != JTokenType.Object) { return; } if (nodes.ContainsKey(tokenName)) nodes[tokenName]++; else nodes.Add(tokenName, 1); } else { if (leafs.ContainsKey(tokenName)) leafs[tokenName]++; else leafs.Add(tokenName, 1); } } } }