Subscribe For Free Updates!

We'll not spam mate! We promise.

Jul 13, 2016

Auto Generate Classes from JSON or XML In Visual studio .Net


It is very hard to convert the JSON or XML output of Web service or Web API to Model or Object Classes manually.

The best way to handle service response data is, to Deserialize the JSON or XML response into class Object.

For this, you need to create mapping classes for that JSON response. Today I will show you how you can easily and quickly created these classes which are auto-generated by a Visual studio.

All you need for this, a Visual studio IDE and JSON or XML Data.
So Lets Start.
First Copy the following JSON Data.
{ "name": "", "address": { "street": "", "city": "", "province": "", "postalCode": "", "country": "" }, "phoneDay": "", "phoneCell": "", "businessName": "", "website": "", "email": "" }
Now Open Visual Studio Create a Dummy Project-> then Create a Dummy Class and clear all code from that class Like Below.

Now From Top Left Menu Go to Edit -> Paste Special -> Select Paste JSON as Class or Paste XML as Class in case you copied XML Data.
Don't  forget to copy JSON data first otherwise, you will not see these option in Edit Menu.

And you will see the Model or Object Class is automatically Generated by the Visual studio. Like Below Image.

That's all we Generated Model Classes from JSON Data.

Visual Studio 2012 (with ASP.NET and Web Tools 2012.2 RC installed) supports this natively.
Visual Studio 2013 onwards have this built-in.
By using the same above steps, you can generate model classes in Visual basic

Thanks for reading.If you have any Question please feel free ask (by entering your queries in comments).

Plese Feel Free to Socializer This Post


Post a Comment

Become a Fan

visual studio learn