Created
September 30, 2011 12:26
Revisions
-
grumpydev created this gist
Sep 30, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,62 @@ using System; using System.Collections.Generic; using System.Linq; namespace JSONTestingAgain { class Program { static void Main(string[] args) { var test = new TestClass { TestGuid = Guid.NewGuid(), TestString = "blah" }; test.TestDictionary.Add("testString", "testStringValue"); test.TestDictionary.Add("testGuid", Guid.NewGuid()); var nancyResult = Nancy(test); var microsoftResult = Microsoft(test); Console.WriteLine(nancyResult); Console.WriteLine(microsoftResult); Console.ReadLine(); } private static TestClass Microsoft(TestClass test) { var serializer = new System.Web.Script.Serialization.JavaScriptSerializer(); var result = serializer.Serialize(test); var newOne = serializer.Deserialize<TestClass>(result); return newOne; } private static TestClass Nancy(TestClass test) { var serializer = new Nancy.Json.JavaScriptSerializer(); var result = serializer.Serialize(test); var newOne = serializer.Deserialize<TestClass>(result); return newOne; } } public class TestClass { public Guid TestGuid { get; set; } public String TestString { get; set; } public Dictionary<string, object> TestDictionary { get; set; } public TestClass() { this.TestDictionary = new Dictionary<string, object>(); } public override string ToString() { return String.Format( "{0} {1} {2}", TestGuid, TestString, this.TestDictionary.Select(kv => kv.Key.ToString() + ":" + kv.Value.ToString()).Aggregate( (kv1, kv2) => kv1 + "," + kv2)); } } }