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

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

  • How to create an OLAP Cube?

    This article will have no theory rather than it will have only be demonstrating practical step by step in detail included to create SSAS OLAP Cube:…

  • Instrumentation is SSIS using Data Taps

    In this short article we will hover around some important questions related to Instrumentation done in SSIS using Data Taps. We will only discuss…

  • Create job using SQL Server Agent step by step.

    In MSBI while working on SSIS projects we have to run repetitive task which has to carried out daily like running package or to take weekly backup…

  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments