.Net Interview Questions and Answers

Search:

QuestPond's interview questions and answers on JSON(JavaScript Object Notation)

By : Shiv Prasad Koirala | Oct 1st, 2014 | Views : 3948 | Comments : 0 Bookmark and Share

Explain how to emit JSON from an ASP.NET Web Forms application?


In Web forms this can be achieved with the help of Http Handlers.


  1. In your web form project create a new Generic Http Handler. Right click the project, Add new Item >> Generic handler (file with ashx extension)

  2. In the ProcessRequest function create and return JSON string as follows


a. Create object of your .net class and initialize properties with values.



b. Create Json string of above object using JavascriptSerializer class as follows



c. Set your return type as JSON and return the above created string.



How to consume that emitted JSON later?


We can use jQuery for that. In jQuery we have some AJAX functions available using which we will be able to make a get/post request to handler created in the above example. In response we will get JavaScript object instead of JSON string.



Why the return value in above example is JavaScript object, why not it is JSON String?


$.getJSON and other AJAX functions in jQuery internally uses XMLHttpRequest object (a core JavaScript Ajax function). In reality after the AJAX call the return value was JSON string but internally jQuery converts that json string to JavaScript object and invoke the done function of it. This is why we get JavaScript object as a parameter in "call back" function passed inside "done" function.


References


www.codeproject.com/Articles/779303/JSON-and-Microsoft-technologies


Looking for training?


(MVC, WCF, Design Patterns, MSBI, JSON, WPF, ALM using VSTS, jQuery, HTML 5)We provide all kinds of trainings on various technologies. Visit www.JustCompile.com for detail.



Also see our video on JSON (JavaScript Object Notation) as follows: -


 
Rate this Article :
1 Star
2 Stars
3 Stars
4 Stars
5 Stars
1 1 1 2 1
 
 
 
 

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

.NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala

In this article we will explain .NET interview questions 6th edition (Sixth edition) - By Shivprasad Koirala.... Read More

Explain MVC application life cycle?

In this article we will explain MVC application life cycle.For more articles and videos visit us on www.questpond.com... Read More

What is the difference between Stored Procedures and Function (SQL Server interview question with answers)?

In this article we will explain what is the difference between Stored Procedures and Function.For more articles and videos visit us on www.questpond.com... Read More

C# Design pattern interview questions with answers: - How Singleton is different from Static class?

In this article we will explain How Singleton is different from Static class.... Read More

WCF interview questions and answers: - What is the difference between Service endpoint and Client endpoint?

In this article we will explain What is the difference between Service endpoint and Client endpoint.... Read More

Article Categories

Learn in Hindi