Before understanding Deserialization JSON we should know what Deserialization means, Deserialization is the process of getting back the serialized object and this helps us to reconstruct an object whenever it is required, now to pass the data between the applications JSON format is required, JSON stands for JAVASCRIPT OBJECT NOTATION, it is very light in weight and it can be read and understood by users very easily and also it is easy for system to parse it and generate the output. There are also different styles of JSON like
1. Object - Example: var Name = {"name":"Ambuj","gender":"Male"}
2. Array – Example: var NameList = ,{"user":{"name":"Kumar","gender":"Male"]]
3. String- Example: var userlist ="{\"Sl\":01,\"Name\":\"Ambuj\",\"Home\":\"Lucknow\"}"
Now to Deserialize a JSON data in C# firstly we have to install package named as “Newtonsoft.Json”, without using this namespace in our C# code we cannot deserialize our JSON, the syntax of deserialization is
First we will create Object:
Blogsite abc = new Blogsite();
String jsonfile = @”{"name":"Ambuj","gender":"Male"}” ;
Now we will write the syntax for deserialization:
Blogsite abc = JsonConvert.DeserializeObject<Blogsite>(jsonfile);
Response.Write(abc.name);
So above is the process by which we can do Deserialization JSON in C#.