2012-03-28 24 views
0

正如问题中所提到的,如何让asp.net页面以JSON格式返回数据?如何让asp.net页面返回JSON数据?

+0

检查出来的答案:

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

对于MVC,你可以在这个页面的操作使用Content方法这SO帖子:http://stackoverflow.com/questions/191881/serializing-to-json-in-jquery – WraithNath 2012-03-28 08:36:44

+0

谢谢,但我很抱歉重复的问题,请你可以哟告诉我如何在发布前搜索所需的问题它呢? – Bader 2012-03-28 08:38:28

+0

您使用的是MVC还是网络表单? – AlexC 2012-03-28 08:39:05

回答

0

更好的是使用HttpHandler。它可以让你输出任何你想要的东西。另一种方法是使用web method,但我不确定它会很容易返回json,而不是XML

1

这取决于您是否使用web表单或MVC。

对于要web表单,你可以只写出来的数据:

return Content("{\"hello\":\"world\"}", "application(json"); 
相关问题