Simple Json C# Correct Way to Deserialize Dictionary

By: Chintan
Updated: April 11, 2014 | Technology: Asp.Net, Tips and Tricks, Web Service
Simple Json C# Correct Way to Deserialize Dictionary

We are using RESTSharp Library to work with third party REST based API. Which by default support XML and JSON deserialization. but their documentation for Deserialization is covered with a limited simple example. which was not sufficient to help us consume Complex JSON output.

We are using http://json2csharp.com/ to convert JSON string to C# class. Which works perfectly when JSON string is in a simple structure. but when it comes to Deserialize to JSON to Dictionary< string, class> then class generated using json2csharp.com fails.

Example:

Consider following complex JSON response which requires Dictionary<string, class>.

JSON:

Copy to Clipboard

Output after converting JSON to C# class using converter tool:

Wrong way to put Dictionary:

Copy to Clipboard

The right way to put Dictionary:

Copy to Clipboard

I hope this article saves time for you.

Thank you…!!