Created
March 1, 2015 03:54
-
-
Save rprakashg/681690760c0baa36fdaf to your computer and use it in GitHub Desktop.
ToJson extension methods for serializing objects to json uses CamelCasePropertyNamesContractResolver so serialized string will follow camel casing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using Newtonsoft.Json; | |
using Newtonsoft.Json.Serialization; | |
public static class JsonExtensionMethods | |
{ | |
public static String ToJson(this object model) | |
{ | |
JsonSerializerSettings settings = new JsonSerializerSettings | |
{ | |
NullValueHandling = NullValueHandling.Ignore, | |
ContractResolver = new CamelCasePropertyNamesContractResolver(), | |
}; | |
return JsonConvert.SerializeObject(model, Formatting.Indented, settings); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment