Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var hierarchy = new List<Hierarchy>();
- var lines = File.ReadAllLines("taxonomy.txt");
- foreach (var line in lines)
- {
- var splitLine = line.Split(" > ").ToList();
- if (splitLine.Count == 1)
- hierarchy.Add(new Hierarchy { Name = splitLine[0], Children = new List<Hierarchy>() });
- var newHierarchy = hierarchy.Find(x => x.Name == splitLine[0]);
- for(int i = 1; i < splitLine.Count; i++)
- {
- if (i == splitLine.Count - 1)
- newHierarchy.Children.Add(new Hierarchy { Name = splitLine[i], Children = new List<Hierarchy>() });
- else
- newHierarchy = newHierarchy.Children.First(x => x.Name == splitLine[i]);
- }
- }
- File.WriteAllLines("output.txt", hierarchy.Select(x => JsonConvert.SerializeObject(x)));
- Console.WriteLine("Hello World!");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement