public static EducationJson LoadJson(string path) { using (StreamReader r = new StreamReader(path)) { string json = r.ReadToEnd(); EducationJson resume = JsonConvert.DeserializeObject <EducationJson>(json); return(resume); } }
public static IList <Education> LoadType(ResumeDbContext context, string path, Boolean writeJson) { // if (File.Exists(filePath)) // { // Console.WriteLine("##############################"); // Console.WriteLine($"{filePath} written to database"); // } // else // { // Console.WriteLine("##############################"); // Console.WriteLine($"No such file at: {filePath}"); // } using (StreamReader r = new StreamReader(path)) { var deserializer = new Deserializer(); var yamlObject = deserializer.Deserialize(r); var serializer = new Newtonsoft.Json.JsonSerializer(); serializer.Formatting = Newtonsoft.Json.Formatting.Indented; string json; using (StringWriter w = new StringWriter()) { serializer.Serialize(w, yamlObject); json = w.ToString(); } if (writeJson) { string jsonPath = path.Replace("yml", "json"); using (StreamWriter w2 = new StreamWriter(jsonPath)) { w2.Write(json); } } // string json = r.ReadToEnd(); EducationJson educations = JsonConvert.DeserializeObject <EducationJson>(json); context.Add(educations.Educations); return(educations.Educations); } }