16

How can I do this in C# modern 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

Greg Sansom
  • 20,442
  • 6
  • 58
  • 76
tovaz
  • 193
  • 1
  • 2
  • 8
  • 1. Could not find the type or namespace name "WebClient" - 2. Could not find the type or namespace name "JavaScriptSerializer" – tovaz Jul 15 '13 at 16:27
  • 1
    possible duplicate of [How to reference JSON serialization in ClassLibrary?](http://stackoverflow.com/questions/3872734/how-to-reference-json-serialization-in-classlibrary) – RajeshKdev Jan 01 '14 at 11:09
  • Related post [here](https://stackoverflow.com/q/1156313/465053) – RBT Nov 12 '17 at 01:23

2 Answers2

64

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

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)

Liquid Core
  • 1
  • 6
  • 27
  • 52
5

I found the System.Web.Script.Serialization in System.Web.Extensions

Naushad CK
  • 51
  • 1
  • 5