× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Handling excessive members when deserializing with C# Json.net

James Jensen
Feb 10, 2015
<p>You should be able to use the [JsonExtensionData] attribute for this: <a href="http://james.newtonking.com/archive/2013/05/08/json-net-5-0-release-5-defaultsettings-and-extension-data" rel="nofollow">http://james.newtonking.com/archive/2013/05/08/json-net-5-0-release-5-defaultsettings-and-extension-data</a></p> <pre><code>void Main() { var str = "{\r\n \"name\":\"Chris\",\r\n \"age\":100,\r\n \"birthplace\":\"UK\",\r\n \"height\":170," + "\r\n \"birthdate\":\"08/08/1913\",\r\n}"; var person = JsonConvert.DeserializeObject&lt;Person&gt;(str); Console.WriteLine(person.name); Console.WriteLine(person.other["birthplace"]); } class Person { public string name; public int age; public int height; [JsonExtensionData] public IDictionary&lt;string, object&gt; other; } </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/25395765/Handling%20excessive%20members%20when%20deserializing%20with%20C#%20Json.net/25395823">Stack Overflow</a>.</p>
comments powered by Disqus