public static void JSONDeserializationDemo() { string json = "{ \"Name\":\"Subham\",\"Description\":\"Welcome to subham's json\"}"; BlogSites bsObj2 = JsonConvert.DeserializeObject <BlogSites>(json); Console.WriteLine(bsObj2.Name + "\n" + bsObj2.Description); }
public static void XmlDeSerializedemo() { string path = @"C:\Users\user\source\repos\fileIODemoLive\xmlser.txt"; XmlSerializer xmlser = new XmlSerializer(typeof(BlogSites)); FileStream fileStream = new FileStream(path, FileMode.Open); BlogSites blogSites = (BlogSites)xmlser.Deserialize(fileStream); Console.WriteLine(blogSites.Name + "\n" + blogSites.Description); fileStream.Close(); }
public static void JSONSerializationDemo() { BlogSites bsObj = new BlogSites() { Name = "Subham", Description = "Welcome to subham's json" }; string jsonData = JsonConvert.SerializeObject(bsObj); Console.WriteLine(jsonData); }
public static void XmlSerializedemo() { string path = @"C:\Users\user\source\repos\fileIODemoLive\xmlser.txt"; XmlSerializer xmlser = new XmlSerializer(typeof(BlogSites)); FileStream fileStream = new FileStream(path, FileMode.Create); BlogSites blogSites = new BlogSites() { Name = "Subham", Description = "Welcome to subham's json" }; xmlser.Serialize(fileStream, blogSites); fileStream.Close(); }