Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find JavaScriptSerializer in .Net 4.0

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?

  • I do know System.Web.Extensions was marked as obsolete in 3.5
like image 245
Prisoner ZERO Avatar asked Aug 09 '11 18:08

Prisoner ZERO


People also ask

What namespace is JavaScriptSerializer in?

Text. Json namespace should be used for serialization and deserialization.

What is JavaScriptSerializer C#?

JavaScriptSerializer is a class that helps to serialize and deserialize JSON. It is present in the namespace System.

Where is System Web script serialization?

Serialization is in the System. Web. Extensions library. Make sure you are using .


2 Answers

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:

  1. Create a new console application
  2. Change the target to .net 4 instead of Client Profile
  3. Add a reference to System.Web.Extensions (4.0)
  4. Have access to JavaScriptSerializer in Program.cs now :-)
like image 72
Steffen Avatar answered Oct 07 '22 12:10

Steffen


  1. Right click References and do Add Reference, then from Assemblies->Framework select System.Web.Extensions.
  2. Now you should be able to add the following to your class file:
    using System.Web.Script.Serialization; 
like image 27
Scott Johnson Avatar answered Oct 07 '22 12:10

Scott Johnson