Generally the longest and most frustrating part of using a 3rd party API is making all the C# classes that the data will plugin to after you make requests into those API’s.
In Visual Studio 2013 2012 (JSON Support added in 2012 Update 2) this experience has changed, you are now able to paste JSON and XML into Visual Studio and have it automatically generate the classes for you. In this article I will be using a sample data from http://www.json.org/example.html.
First up you need to open a new application, I created a new console application. I’m going to be using the sample JSON below
Generating classes
Now all that is required from this to create you classes is make sure the JSON is in your clipboard, place your cursor somewhere in a file, go to Edit > Paste Special > Paste JSON as classes.
With this Simple example the classes below are generated
This will also work for XML so taking the XML
and then going to Edit > Paste Special > Paste XML as classes will generate
Loading generated JSON objects
To load the generated JSON objects all you need to do is use the JavaScriptSerializer as in the below 2 lines.
When you run this piece of code you will notice that the object has been populated with the JSON.
Enjoy
Hope this is useful and that many people already know about this great feature and that if you have been manually creating classes that you now have many free hours to do other things with.