J query

json serialization and deserialization – C#

json serialization and deserialization in c#

Best way to work with json and c# using Serialization and  Deserialization

Json String :

{“user”: {“Fname”:”Mahesh”,”Lname”:”Javiya”}}

Class In C# :

public class User
    public string Fname { get; set; }
    public string Lname { get; set; }

public class RootObject
    public User user { get; set; }

Online Convert Json string to C# class :

Code to Serialization and Deserialize : 

Serialize :

var json = jss.Serialize(RootObject);

Deserialize :

using System.Web.Script.Serialization;

var jss = new JavaScriptSerializer();
RootObject objRoot = jss.Deserialize<RootObject>(jsonText);

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.