Convert JSON into c# classes very simple with web tools 2012.RC
Conevrt json in to c# classes objects very simple with web tools 2012.RC
Today i found very nice feature in visual studio web tools 2012.RC
Is the convert your json c# class objects
There is a feature added in 2012 web tools rc is "Paste JSON as classes".with this tools enable in your machine you will get the Special paste options
Where can i find this option
In visual studio main menu edit at the last menu item is paste special there you can find the "Paste as json classes"
This option can convert JSON To C#and VB classes
These are the following conversion rules will be consider while pasting
- Outer most class name is the root class
- All classes and properties are public properties
- if property is a key word it prefix with _
- in properties is number its converts in to int/flaot/double
- bool values are converts in to vb/c# bollean datatype
Lets Look an example
JSON object
{ "link": "http://www.microsoft.com/Surface/en-US", /*Awesome*/ "virtual": "Virtual Keyboard", "partial": " The magnesium panels are finished with partial vapor deposition", "Price": 499.99, "title": "Microsoft Surface", "शीर्षक": "माइक्रोसॉफ्ट सरफेस", "Like": true, "cdDrive":null, }
C# class for above JSON object will look like below.public class Rootobject { public string link { get; set; } public string _virtual { get; set; } public string partial { get; set; } public float Price { get; set; } public string title { get; set; } public string शीर्षक { get; set; } public bool Like { get; set; } public object cdDrive { get; set; } }
Labels:
C#