static void Main(string[] args) { DailyHighScores dailyHighScores = new DailyHighScores { Date = new DateTime(2016, 6, 27, 0, 0, 0, DateTimeKind.Utc), Game = "Donkey Kong", UserPoints = new UserPointsDictionary <string, int> { { "JamesNK", 9001 }, { "JoC", 1337 }, { "JessicaN", 1000 } } }; DefaultContractResolver contractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy { ProcessDictionaryKeys = true } }; string json = JsonConvert.SerializeObject(dailyHighScores, new JsonSerializerSettings { ContractResolver = contractResolver, Formatting = Formatting.Indented }); Console.WriteLine(json); Console.Read(); }
public void Example() { #region Usage DailyHighScores dailyHighScores = new DailyHighScores { Date = new DateTime(2016, 6, 27, 0, 0, 0, DateTimeKind.Utc), Game = "Donkey Kong", UserPoints = new Dictionary <string, int> { ["JamesNK"] = 9001, ["JoC"] = 1337, ["JessicaN"] = 1000 } }; DefaultContractResolver contractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy { ProcessDictionaryKeys = false } }; string json = JsonConvert.SerializeObject( dailyHighScores, new JsonSerializerSettings { ContractResolver = contractResolver, Formatting = Formatting.Indented } ); Console.WriteLine(json); // { // "date": "2016-06-27T00:00:00Z", // "game": "Donkey Kong", // "userPoints": { // "JamesNK": 9001, // "JoC": 1337, // "JessicaN": 1000 // } // } #endregion StringAssert.AreEqual( @"{ ""date"": ""2016-06-27T00:00:00Z"", ""game"": ""Donkey Kong"", ""userPoints"": { ""JamesNK"": 9001, ""JoC"": 1337, ""JessicaN"": 1000 } }", json ); }
public void Example() { #region Usage DailyHighScores dailyHighScores = new DailyHighScores { Date = new DateTime(2016, 6, 27, 0, 0, 0, DateTimeKind.Utc), Game = "Donkey Kong", UserPoints = new Dictionary<string, int> { ["JamesNK"] = 9001, ["JoC"] = 1337, ["JessicN"] = 1000 } }; DefaultContractResolver contractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy { ProcessDictionaryKeys = false } }; string json = JsonConvert.SerializeObject(dailyHighScores, new JsonSerializerSettings { ContractResolver = contractResolver, Formatting = Formatting.Indented }); Console.WriteLine(json); // { // "date": "2016-06-27T00:00:00Z", // "game": "Donkey Kong", // "userPoints": { // "JamesNK": 9001, // "JoC": 1337, // "JessicN": 1000 // } // } #endregion StringAssert.AreEqual(@"{ ""date"": ""2016-06-27T00:00:00Z"", ""game"": ""Donkey Kong"", ""userPoints"": { ""JamesNK"": 9001, ""JoC"": 1337, ""JessicN"": 1000 } }", json); }