Free programming examples and instructions

Asp.net- C# List object to json string

Demo and Code for how to convert C# List object to json string

by Athil

Posted on 27 Jul 2018 Category: Asp.net Views: 1294

Here I am going to show how to convert C# list To JSON string.


For this, I am having a data model of UserDetails.

 public class UserDetails
            public string Name { get; set; }
            public string Email { get; set; }
            public string PhoneNumber { get; set; }
            public string SessionTime { get; set; }



 <form id="form1" runat="server">
        Enter Name:&nbsp;
        <asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
        <br />
        <br />
        Email :<asp:TextBox ID="TxtEmail" runat="server"></asp:TextBox>
&nbsp;<br />
        <br />
        Phone Number :
        <asp:TextBox ID="TxtPhoneNumber" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Submit" />

C# Code

 protected void Button1_Click(object sender, EventArgs e)
            UserDetails ud = new UserDetails();
            ud.Name = TxtName.Text;
            ud.Email = TxtEmail.Text;
            ud.PhoneNumber = TxtPhoneNumber.Text;
            ud.SessionTime = DateTime.Now.ToString();

            string data = new JavaScriptSerializer().Serialize(ud);



Leave a Comment:

Click here to register

Popular articles