Reputation: 14176
I cannot seem to find the JavaScriptSerializer
object nor the the System.Web.Script.Serialization
namespace within Visual Studio 2010. I need to serialize something to JSON what am I supposed to use?
And yes, I already included the System.Web.Extensions
(in System.Web.Extensions.dll) within the project. Which is why I am shocked?
System.Web.Extensions
was marked as obsolete in 3.5Upvotes: 310
Views: 357873
Reputation: 20421
I'm using Visual Studio 2015 and finally ran across this post.
Yes in order to use
JavaScriptSerializer json = new JavaScriptSerializer();
You must right click on references and under Assemblies --> Framework choose
System.Web.Extensions
Then add in your reference
using System.Web.Script.Serialization;
Upvotes: 32
Reputation: 3011
You can use another option which is the Newtonsoft.Json, you can install it from NuGet Package Manager.
Tools >> Nuget Package Manager >> Package Manager Console by issuing command
Install-Package Newtonsoft.Json
or
by using the GUI at Tools >> Nuget Package Manager >> Manage NuGet Packages for Solution...
Upvotes: 5
Reputation: 13958
Check if you included the .net 4 version of System.Web.Extensions
- there's a 3.5 version as well, but I don't think that one works.
These steps work for me:
System.Web.Extensions
(4.0)JavaScriptSerializer
in Program.cs now :-)Upvotes: 545
Reputation: 2878
using System.Web.Script.Serialization;
is in assembly : System.Web.Extensions (System.Web.Extensions.dll)
Upvotes: 13
Reputation: 3335
Just so you know, I am using Visual Studio 2013 and have had the same problem until I used the Project Properties to switch to 3.5 framework and back to 4.5. This for some reason registered the .dll properly and I could use the System.Web.Extensions.
Upvotes: 3
Reputation: 4530
From the first search result on google:
http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
JavaScriptSerializer Class
Provides serialization and deserialization functionality for AJAX-enabled applications.
Inheritance Hierarchy
System.Object
System.Web.Script.Serialization.JavaScriptSerializer
Namespace: System.Web.Script.Serialization
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
So, include System.Web.Extensions.dll
as a reference.
Upvotes: 43
Reputation: 12544
For those who seem to be following the answers above but still have the problem (e.g., see the first comment on the poster's question):
You are probably working in a solution with many projects. The project you appear to be working in references other projects, but you are actually modifying a file from one of the other projects. For example:
System.Web.Extensions
But if the file you are modifying to use System.Web.Script.Serialization
is in project B, then you will need to add a reference to System.Web.Extension
in project B as well.
Upvotes: 9
Reputation: 1510
References
and do Add Reference
, then from Assemblies->Framework
select System.Web.Extensions
. using System.Web.Script.Serialization;
Upvotes: 141
Reputation: 878
You have to add the reference to the project.
In Assemblies, there is a System.Web.Extensions Add that.
Once that is done put:
using System.Web;
using System.Web.Script;
using System.Web.Script.Serialization;
That worked for me.
Upvotes: 5
Reputation: 890
This is how to get JavaScriptSerializer available in your application, targetting .NET 4.0
(full)
using System.Web.Script.Serialization;
This should allow you to create a new JavaScriptSerializer
object!
Upvotes: 14
Reputation: 31606
Did you include a reference to System.Web.Extensions
? If you click on your first link it says which assembly it's in.
Upvotes: 8
Reputation: 30725
Are you targeting the .NET 4 framework or the .NET 4 Client Profile?
If you're targeting the latter, you won't find that class. You also may be missing a reference, likely to an extensions dll.
Upvotes: 9