Newtonsoft Json : Convert dynemic Object to Json string
// Create Dynemic Object var msgParams = new { Message = "Contact is associated with property successfully.", UpdateSection = "PropertyContacts", ReloadFullPage = "false" }; // Convert Dynemic object to json string string jsonString = JsonConvert.SerializeObject(msgParams, Formatting.Indented);Serializing and Deserializing JSON with JsonConvert
Product product = new Product(); product.Name = "Apple"; product.ExpiryDate = new DateTime(2008, 12, 28); product.Price = 3.99M; product.Sizes = new string[] { "Small", "Medium", "Large" }; string output = JsonConvert.SerializeObject(product); //{ // "Name": "Apple", // "ExpiryDate": "2008-12-28T00:00:00", // "Price": 3.99, // "Sizes": [ // "Small", // "Medium", // "Large" // ] //} Product deserializedProduct = JsonConvert.DeserializeObject(output);
No comments:
Post a Comment