Created
June 15, 2016 18:27
-
-
Save embarq/a5766704418e420e5e48b82e4007e61b to your computer and use it in GitHub Desktop.
JSON Import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string[] files = Directory.GetFiles(@"../../", "*.json"); | |
foreach(string filename in files) | |
{ | |
Console.WriteLine("File: " + filename); | |
List<dynamic> data = import(filename); | |
foreach(dynamic subset in data) | |
{ | |
foreach (JProperty prop in subset.Properties()) | |
{ | |
Console.WriteLine('\t' + prop.Name + ": " + prop.Value); | |
} | |
} | |
Console.WriteLine(""); | |
} | |
Console.ReadLine(); | |
} | |
static List<dynamic> import(string filename) | |
{ | |
//Dictionary<string, string> data = new Dictionary<string, string>(); | |
List<dynamic> data = new List<dynamic>(); | |
dynamic jsonData = JArray.Parse(File.ReadAllText(filename)); | |
foreach (dynamic item in jsonData) | |
{ | |
data.Add(new JObject(item)); | |
} | |
return data; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment