16

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?

dandan78
14k13 gold badges67 silver badges82 bronze badges
asked Sep 11, 2013 at 16:00
1
  • 1
    Welcome to Stackoverflow, Jeff. Please note that this is not a forum so the usual forum-style introductions (I'm a newbie etc) plus tags in the title are neither necessary nor desirable here. Have a look at the faq and the how to How to Ask pages for more information. Also try to get the formatting right in your question. Commented Sep 11, 2013 at 16:10

5 Answers 5

32

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)

answered Sep 11, 2013 at 16:04

Comments

4
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

answered Jun 14, 2014 at 13:16

Comments

4

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/

answered Jan 6, 2018 at 19:41

Comments

0

I have had this problem and I added project reference for System.Web.Extensions , try adding that reference to your project and see if it helps

answered Sep 11, 2013 at 16:05

Comments

-3

install Desharp package you can use this command in package manager console

Install-Package Desharp -Version 1.2.11

answered Dec 16, 2017 at 14:06

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.