如何在C#中执行System.Web.Script.Serialization?

tov*_*vaz 15 c# json javascriptserializer downloadstring system.web

我怎样才能在C#现代UI中做到这一点?

var url = "http://ajax.googleapis.com/ajax/services/feed/load?q=http%3A%2F%2Fwww.digg.com%2Frss%2Findex.xml&v=1.0";
var wc = new WebClient();
var rawFeedData = wc.DownloadString(url);

//You can use System.Web.Script.Serialization if you don't want to use Json.NET
JavaScriptSerializer ser = new JavaScriptSerializer();
FeedApiResult foo = ser.Deserialize<FeedApiResult>(rawFeedData);

//Json.NET also return you the same strong typed object     
var apiResult = JsonConvert.DeserializeObject<FeedApiResult>(rawFeedData);
Run Code Online (Sandbox Code Playgroud)

它给我在WebClient和错误中的错误 System.Web.Script.Serialization

Liq*_*ore 57

我找到了如何使它工作.
我不知道为什么他们这么乱,我甚至不明白为什么,但这里是解决方案:右键点击项目并添加对以下内容的引用:

System.Web.Extensions程序

比你可以添加你需要的参考:

using System.Web.Script.Serialization;
Run Code Online (Sandbox Code Playgroud)

这次它会起作用.(至少这是我在.NET framework 3.5上所做的)

  • 也在4.0中工作. (3认同)

小智 5

我在 System.Web.Extensions 中找到了 System.Web.Script.Serialization