static Authors GetObject(string result) { Authors aresult = null; try { aresult = JsonConvert.DeserializeObject <Authors>(result); Console.WriteLine($"Name: {aresult.AuthorName}, Skills = {aresult.Skills}, DOB = {aresult.DOB}"); } catch (Exception ex) { Console.WriteLine($"Error validating json: {ex.Message}"); } return(aresult); }
static void Main(string[] args) { System.Console.WriteLine("Press any key to start execution."); System.Console.ReadKey(); ParseSamples ps = new ParseSamples(); switch (args.Length) { case 1: ps.ProcessBool(args[0]); break; case 2: ps.ProcessBool(args[0]); ps.ProcessInteger(args[1]); break; default: Console.WriteLine("Please provide one or two command line arguments"); break; } ps.ConvertSample(); RegularExpressionSamples res = new RegularExpressionSamples(); res.ReplacePatternText(); res.MatchPatternText(); res.IsMatchPattern(); Student st = new Student(); st.FullName = "st1"; st.EmailAddress = "st@st"; st.DOB = DateTime.Now; ValidationContext context = new ValidationContext(st, null, null); List <ValidationResult> results = new List <ValidationResult>(); bool valid = Validator.TryValidateObject(st, context, results, true); if (!valid) { foreach (ValidationResult vr in results) { Console.Write("Student class Property Name :{0}", vr.MemberNames.First()); Console.Write(" :: {0}{1}", vr.ErrorMessage, Environment.NewLine); } } Console.Write("Loading and validating XML...."); LoadXML(); Console.Write("Loading JSON...."); string result = GetJson(); Authors a = GetObject(result); Console.Write("concatinating extra text to JSON...."); string result1 = string.Concat(result, "Test"); Console.Write("deserializing JSON...."); Authors a1 = GetObject(result1) ?? null; // Keep the console window open in debug mode. System.Console.WriteLine("Press any key to exit."); System.Console.ReadKey(); }