Asp.net J query

json serialization and deserialization – Asp.net C#

json serialization and deserialization in asp.net c#

Best way to work with json and asp.net 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 :
http://json2csharp.com/


Code to Serialization and Deserialize : 

Serialize :

var json = jss.Serialize(RootObject);
Console.WriteLine(json);

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.