如何在asp.net mvc 3中使用非wcf rest服务?
我使用Webmatrix编写了一个简单的web服务,它以json格式返回数据。我喜欢使用ASP.NETMVC3使用该服务。我知道如何用WCF做到这一点,但我们不会在这个项目上使用WCF。是否有类似于ASP.NET MVC中jquery的getJson()方法的东西,我只是传入restful url,它返回数据,然后我在回调中处理它?谢谢您的帮助:-) 这是我的服务: 网址: 代码: 您可以使用从远程资源获取JSON数据。例如:如何在asp.net mvc 3中使用非wcf rest服务?,asp.net,asp.net-mvc,web-services,asp.net-mvc-3,Asp.net,Asp.net Mvc,Web Services,Asp.net Mvc 3,我使用Webmatrix编写了一个简单的web服务,它以json格式返回数据。我喜欢使用ASP.NETMVC3使用该服务。我知道如何用WCF做到这一点,但我们不会在这个项目上使用WCF。是否有类似于ASP.NET MVC中jquery的getJson()方法的东西,我只是传入restful url,它返回数据,然后我在回调中处理它?谢谢您的帮助:-) 这是我的服务: 网址: 代码: 您可以使用从远程资源获取JSON数据。例如: using (var client = new WebClient(
using (var client = new WebClient())
{
string json = client.DownloadString("http://example.com/services/GetAllItemsService");
// TODO: do something with this JSON data, like for example deserialize into a model
var serializer = new JavaScriptSerializer();
var model = serializer.Deserialize<SomeModel>(json);
}
看看RESTSharp:
- 使用一些库,比如
- 使用WebClient检索数据并使用JSON反序列化程序,如
或JavaScriptSerializer
@{
var items = ItemsService.GetAllItems();
Json.Write(items, Response.Output);
}
using (var client = new WebClient())
{
string json = client.DownloadString("http://example.com/services/GetAllItemsService");
// TODO: do something with this JSON data, like for example deserialize into a model
var serializer = new JavaScriptSerializer();
var model = serializer.Deserialize<SomeModel>(json);
}
using (var client = new WebClient())
{
string json = client.DownloadString("http://example.com/services/GetAllItemsService");
Response.Output.Write(json);
}