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?
install Desharp package you can use this command in package manager console
Install-Package Desharp -Version 1.2.11
JavaScriptSerializer
is situated inSystem.Web.Extensions
Assembly. You should add it to your project references.You can get this information in MSDN
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/
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 helpsThis will help you to get the value