0

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

5
  • Check out the answer in this SO post: stackoverflow.com/questions/191881/… Commented Mar 28, 2012 at 8:36
  • Thanks, but I m sorry to duplicate the question, please can yo tell me how to search the required question before posting it ? Commented Mar 28, 2012 at 8:38
  • Are you using MVC or webforms? Commented Mar 28, 2012 at 8: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 :) Commented Mar 28, 2012 at 8:41
  • I think the most relevant SO question is stackoverflow.com/questions/5364343/… Commented Mar 28, 2012 at 8:47

3 Answers 3

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/

Sign up to request clarification or add additional context in comments.

Comments

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");

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.