JSON Serialization/Deserialization using C#.NET

Many a times, we have a need to call third party API or web services and these apis and web services return us data in xml format or JSON format.
The .NET Framework doesn’t give you the tools to do it out-of-the-box.

We can implement JSON Serialization/Deserialization in the three ways:

  • Using JavaScriptSerializer class
  • Using DataContractJsonSerializer class
  • Using JSON.NET library 

This demo would highlight how can we deserialize these objects using
JSON.NET package in nuget package manager.

Json.NET is a package which helps conversion between JSON text and .NET object using the JsonSerializer. It converts .NET objects into their JSON equivalent text and back again by mapping the .NET object property names to the JSON property names.

We will install this package in our project.

Go to Tools Menu -> Choose Library Package Manager -> Package Manager Console. It opens a command window to put the following command.

Install-Package Newtonsoft.Json

In our project we are calling fitbit api and getting heart rate data as httpwebresponse in JSON format. Screenshots below.

More information on Newtonsoft Json – https://www.newtonsoft.com/json

Leave a Reply