0

As mentioned in the question, How to make asp.net page returns data in JSON format ?

Bader
  • 3,656
  • 9
  • 38
  • 55
  • Check out the answer in this SO post: http://stackoverflow.com/questions/191881/serializing-to-json-in-jquery – WraithNath Mar 28 '12 at 08:36
  • Thanks, but I m sorry to duplicate the question, please can yo tell me how to search the required question before posting it ? – Bader Mar 28 '12 at 08:38
  • Are you using MVC or webforms? – AlexC Mar 28 '12 at 08:39
  • @AdhamEnaya - When typing the question to post on SO, previous questions will be displayed, you can also use the search bar at the top of SO. In this case I just googled it and a stack overflow page came up with the answer :) I didnt want to duplicate the question which is why I just commented :) – WraithNath Mar 28 '12 at 08:41
  • I think the most relevant SO question is http://stackoverflow.com/questions/5364343/asp-net-web-forms-json-return-result – AlexC Mar 28 '12 at 08:47

3 Answers3

3

Insteed of response with HTML you can response with some JSON. What I think you want to do is adding an interface which can response with JSON.

With .NET you can use webservice which response in JSON format, have a look on this article:

http://encosia.com/using-jquery-to-consume-aspnet-json-web-services/

Simon Edström
  • 6,461
  • 7
  • 32
  • 52
1

That depends on whether you are using webforms or MVC.

For webforms you can just write out the data that you want:

Response.Clear(); // not needed it you have an empty page markup
Response.ContentType = "application/json";
Response.Write("{\"hello\":\"world\"}");
Response.End();

For MVC you can use the Content method in the action for the page:

return Content("{\"hello\":\"world\"}", "application(json");
Guffa
  • 687,336
  • 108
  • 737
  • 1,005
0

Better for is to use HttpHandler. It allows you to output anything you want. Alternative way is to use web method, but I'm not sure that its going to be easy to return json, not XML

Sly
  • 15,046
  • 12
  • 60
  • 89