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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17647563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 10:05:26  来源:igfitidea点击:

How can I do System.Web.Script.Serialization in C#?

c#jsonjavascriptserializersystem.webdownloadstring

提问by tovaz

How can I do this in C# modern UI ?

我怎样才能在 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);

It gives me error an error in WebClient and System.Web.Script.Serialization

它给了我一个错误 WebClient 和 System.Web.Script.Serialization

回答by Liquid Core

I found how to make it work.
I don't know why they did this mess and I don't even understand why but here's the solution: Right click on project and add reference to:

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

System.Web.Extensions

系统.Web.扩展

than you can add the reference you need with:

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

using System.Web.Script.Serialization;

and this time it will work. (At least this is what I did on .NET framework 3.5)

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