【发布时间】:2012-05-23 02:50:32
【问题描述】:
我以前没有这样做过,所以需要一些线索。我有一个 ASP.NET MVC4(测试版)项目 - 移动项目 - 设置。我得到了一组 REST API 来使用。我该怎么做? API 以 JSON 格式返回数据。您有任何示例、最佳做法...?
【问题讨论】:
标签: asp.net-mvc json jquery-mobile
我以前没有这样做过,所以需要一些线索。我有一个 ASP.NET MVC4(测试版)项目 - 移动项目 - 设置。我得到了一组 REST API 来使用。我该怎么做? API 以 JSON 格式返回数据。您有任何示例、最佳做法...?
【问题讨论】:
标签: asp.net-mvc json jquery-mobile
您可以使用$.ajax 方法向服务器上的 Web Api 控制器发送 AJAX 请求:
$.ajax({
url: 'api/values/123',
type: 'GET',
success: function(data) {
// if the controller returned JSON data, the data argument
// will represent a javascript object that you could directly
// access its properties
}
});
【讨论】:
使用WebClient 类的DownloadString 方法。这将为您提供 RESTURL 返回的字符串输出。您可以将其转换为 Json 并迭代结果
string address="http://yourrestdomain/customer/234";
WebClient client = new WebClient ();
string reply = client.DownloadString (address);
【讨论】: