Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScriptSerializer namespace issue

I am having a problem trying to implement the JavaScriptSerializer to parse a JSON string received from a server.

I implemented the following code:

responseFromServer = readStream.ReadLine();
JavaScriptSerializer ser = new JavaScriptSerializer();
var dict = new JavaScriptSerializer().Deserialize<Dictionary<string, object>>(responseFromServer);
var status = dict["notificationType"]; 
Debug.WriteLine(status);

I added using System.Web.Script.Serialization;

Visual C# 2010 Express is telling me the namespace name Script does not exist in the namespace System.Web. As a result the JavaScriptSerializer is not valid.

What am I missing to use this, or is there a better way to parse the JSON string?

like image 544
Jeff Avatar asked Sep 11 '13 16:09

Jeff


3 Answers

JavaScriptSerializer is situated in System.Web.Extensions Assembly. You should add it to your project references.

You can get this information in MSDN

Assembly: System.Web.Extensions (in System.Web.Extensions.dll)

like image 167
Dmitrii Dovgopolyi Avatar answered Oct 23 '22 01:10

Dmitrii Dovgopolyi


System.Web.Script.Serialization.JavaScriptSerializer oSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
var dict = oSerializer.Deserialize<Dictionary<string, object>>(responseFromServer);

This will help you to get the value

like image 42
Lijin Durairaj Avatar answered Oct 23 '22 03:10

Lijin Durairaj


Add Reference System.Web.Extensions

then type using System.Web.Script.Serialization;

Now you should get JavaScriptSerializer valid.

You can use better approach by adding Newtonsoft.Json.dll through

Add Reference. See details here : http://json.codeplex.com/

like image 4
Md Shahriar Avatar answered Oct 23 '22 01:10

Md Shahriar