Skip to content

Instantly share code, notes, and snippets.

@asith-w
Created August 31, 2016 04:58
Show Gist options
  • Save asith-w/22c7d1092ca372e497b311f10bc00380 to your computer and use it in GitHub Desktop.
Save asith-w/22c7d1092ca372e497b311f10bc00380 to your computer and use it in GitHub Desktop.
C# -json JsonSerializerSettings
Product product = new Product
{
ExpiryDate = new DateTime(2010, 12, 20, 18, 1, 0, DateTimeKind.Utc),
Name = "Widget",
Price = 9.99m,
Sizes = new[] {"Small", "Medium", "Large"}
};
string json =
JsonConvert.SerializeObject(
product,
Formatting.Indented,
new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }
);
//{
// "name": "Widget",
// "expiryDate": "\/Date(1292868060000)\/",
// "price": 9.99,
// "sizes": [
// "Small",
// "Medium",
// "Large"
// ]
//}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment