public void Deserialize() { string json = @"{ 'Name': 'C-sharpcorner', 'Description': 'Share Knowledge' }"; //JsonConvert - Provides methods for converting between .NET types and json types. //DeserializeObject() - Deseralize the json object to a specify .Net type. BlogSites bsObj = JsonConvert.DeserializeObject <BlogSites>(json); Console.WriteLine(bsObj.Name); Console.ReadLine(); }
public void DeSerialize(string jsonData) { JavaScriptSerializer js = new JavaScriptSerializer(); BlogSites blogObject = js.Deserialize <BlogSites>(jsonData); string name = blogObject.Name; string description = blogObject.Description; //Other way to without help of BlogSites class dynamic blogObject1 = js.Deserialize <dynamic>(jsonData); string name1 = blogObject1["Name"]; string discription1 = blogObject1["Description"]; Console.ReadLine(); }
public void Serialize() { BlogSites bsObj = new BlogSites() { Name = "C-sharpcorner", Description = "Share Knowledge" }; //Convert BlogSites object to JSON string format //JsonConvert - Provides methods for converting between json types and .net types. //SerializeObject() - serializes the specified object to a JSON string. string jsonData = JsonConvert.SerializeObject(bsObj); Console.Write(jsonData); Console.ReadLine(); }
public string Serialize() { BlogSites bsObj = new BlogSites() { Name = "C-sharpcorner", Description = "Share Knowledge" }; //Serializing object to json data JavaScriptSerializer js = new JavaScriptSerializer(); string jsonData = js.Serialize(bsObj); Console.WriteLine(jsonData); Console.ReadLine(); return(jsonData); }