?

Log in

Previous Entry | Next Entry

JSON is a lightweight way of data exchange between two entities. If you want your ASP.NET page to emit JSON data, you need to use namespace “System.Runtime.Serialization” namsepace. To convert your c# classes to light weight JSON format we need to use “DataContractJsonSerializer” class as shown in the below code snippet.

Person myPerson = new Person("Chris", "Pietschmann");
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(myPerson.GetType());
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, myPerson);
string json = System.Text.Encoding.UTF8.GetString(ms.ToArray());
Response.Clear();
Response.ContentType = "application/json;charset=utf-8";
Response.Write(json);
Response.End();

We have seen people asking interview questions on REST after JSON questions. Below is a simple .NET interview question video with answer which talks about what is REST ?.



Also read this interesting ASP.NET interview question with answer on Server.Transfer and Response.Redirect ?
Copy right www.questpond.com

Buy 600+ Real Time Interview Videos

Call +91-22-66752917 or mail us on questpond@questpond.com for more details on C#, .NET, ASP.NET, SQL Server interview question videos.

SQL Server interview question videos

Latest Month

January 2017
S M T W T F S
1234567
891011121314
15161718192021
22232425262728
293031    

Tags

Powered by LiveJournal.com