private static void writetoCSV(rootobject orders) { string filename = "Orders.csv"; var csv = new StringBuilder(); var Header = "OrderID|OrderDate|Toppings|IsToppingVegetarian"; csv.AppendLine(Header); foreach (var list in orders.orders) { Guid id = Guid.NewGuid(); var first = id; var second = list.orderDate.ToString(); string toppings = string.Join(",", list.toppings.ToArray()); var third = toppings; var fourth = IsVegetarian(list.toppings); var newLine = first + "|" + second + "|" + third + "|" + fourth; csv.AppendLine(newLine); } File.WriteAllText(filename, csv.ToString()); Console.WriteLine("Written CSV File"); }
private static rootobject loadJSONfile() { using (System.IO.StreamReader r = new System.IO.StreamReader("orders.json")) { string json = r.ReadToEnd(); var dateTimeConverter = new IsoDateTimeConverter { DateTimeFormat = "dd/MM/yyyy HH:mm:ss" }; rootobject result = Newtonsoft.Json.JsonConvert.DeserializeObject <rootobject>(json, dateTimeConverter); Console.WriteLine("Read Json File"); return(result); } }