Convert JSON string to net object











>> YOUR LINK HERE: ___ http://youtube.com/watch?v=h286nfsSejY

Link for all dot net and sql server video tutorial playlists • https://www.youtube.com/user/kudvenka... • Link for slides, code samples and text version of the video • http://csharp-video-tutorials.blogspo... • Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help. •    / @aarvikitchen5572   • In this video we will discuss • 1. How to convert .NET object to JSON string • 2. How to convert a JSON string to .NET object • We will be using the following Employee class • public class Employee • { • public string firstName { get; set; } • public string lastName { get; set; } • public string gender { get; set; } • public int salary { get; set; } • } • Replace lt; with LESSTHAN symbol and gt; with GREATERTHAN symbol • The following example converts List lt;Employee gt; objects to a JSON string. Serialize() method of JavaScriptSerializer class converts a .NET object to a JSON string. JavaScriptSerializer class is present in System.Web.Script.Serialization namespace. • using System; • using System.Collections.Generic; • using System.Web.Script.Serialization; • namespace Demo • { • public partial class WebForm1 : System.Web.UI.Page • { • protected void Page_Load(object sender, EventArgs e) • { • Employee employee1 = new Employee • { • firstName = Todd , • lastName = Grover , • gender = Male , • salary = 50000 • }; • Employee employee2 = new Employee • { • firstName = Sara , • lastName = Baker , • gender = Female , • salary = 40000 • }; • List lt;Employee gt; listEmployee = new List lt;Employee gt;(); • listEmployee.Add(employee1); • listEmployee.Add(employee2); • JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); • string JSONString = javaScriptSerializer.Serialize(listEmployee); • Response.Write(JSONString); • } • } • } • Output : • [{ firstName : Todd , lastName : Grover , gender : Male , salary :50000},{ firstName : Sara , lastName : Baker , gender : Female , salary :40000}] • The following example converts a JSON string to List lt;Employee gt; objects. Deserialize() method of JavaScriptSerializer class converts a JSON string to List lt;Employee gt; objects. • string jsonString = [{\\ firstName\\ :\\ Todd\\ ,\\ lastName\\ :\\ Grover\\ ,\\ gender\\ :\\ Male\\ ,\\ salary\\ :50000},{\\ firstName\\ :\\ Sara\\ ,\\ lastName\\ :\\ Baker\\ ,\\ gender\\ :\\ Female\\ ,\\ salary\\ :40000}] ; • JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); • List lt;Employee gt; employees = (List lt;Employee gt;)javaScriptSerializer.Deserialize(jsonString, typeof(List lt;Employee gt;)); • foreach(Employee employee in employees) • { • Response.Write( First Name = + employee.firstName + lt;br/ gt; ); • Response.Write( Last Name = + employee.lastName + lt;br/ gt; ); • Response.Write( Gender = + employee.gender + lt;br/ gt; ); • Response.Write( Salary = + employee.salary + lt;br/ gt; lt;br/ gt; ); • }

#############################












Content Report
Youtor.org / YTube video Downloader © 2025

created by www.youtor.org