我使用这些操作创建了一个带有家庭 Controller 的简单 mvc3 站点。
public JsonResult Param(string id)
{
string upper = String.Concat(id, "ff");
return Json(upper);
}
public ContentResult Param2(string id)
{
string upper = String.Concat(id, "ff");
return Content( upper);
}
public JsonResult Param3(string id)
{
string upper = String.Concat(id, "ff");
io gg = new io();
gg.IOName = upper;
return Json(gg);
}
}
public class io
{
public string IOName {get;set;}
}
如何使用 c# webrquest 获取 json 并发布到这些操作 url???
最佳答案
Darin 的回答很好...但是如果您希望从返回 JSON 负载的方法中获取结果,并且您希望在 C# 中使用...我会这样做:
var client = new WebClient();
var result = client.DownloadString("http://foo.com/home/param3/SomeID");
var serialzier = new JavaScriptSerializer();
io MyIOThing = serialzier.Deserialize<io>(result);
从那里,您可以访问 MyIOThing.IOName
。
JavaScriptSerializer
位于 System.Web.Extensions
程序集中,在 System.Web.Script.Serialization
命名空间中。
关于c# - 使用 c# webrequest 与 asp.net mvc 3 网站进行交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7779824/