Click below for Step by Step and Interview Q & A (dotnetinter) wrote,
Click below for Step by Step and Interview Q & A

ASP.NET JSON interview question with answer: - How to send JSON format from ASP.NET?

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.ContentType = "application/json;charset=utf-8";

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 ?
Tags: .net interview questions and answers, interview question with answers, json interview question and, emit json using, information technology questions, rest interview questions

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded