c# - 使用 c# webrequest 与 asp.net mvc 3 网站进行交互

标签 c# asp.net-mvc json webrequest

我使用这些操作创建了一个带有家庭 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/

相关文章:

c# - 从 DataGrid 而不是从 csv 文件读取到数组/列表

c# - Asp.net 功能中是否存在带有验证器的电子邮件?

c# - 找不到 ASP.NET View

java - 如何使用JAVA(使用javax.json)合并JsonObjects;

c# - 将带有数组的 json 结构展平为多个没有数组的平面对象

C# + SQL Server - 将新行读入内存的最快/最有效的方法

c# 密码导致提交时出现危险请求

asp.net - 将 WebSecurity 与 NHibernate 和 Postgresql 结合使用?

javascript - 将 html 从单独的文件加载到模式对话框中

json - cloudformation 无法创建子网