No se puede encontrar JavaScriptSerializer in.Net 4,0


Parece que no puedo encontrar el JavaScriptSerializer objeto ni el espacio de nombres System.Web.Script.Serialization dentro de Visual Studio 2010. Necesito serializar algo a JSON ¿qué se supone que debo usar?

Y sí, ya he incluido el System.Web.Extensions (en el Sistema.Web.Ampliación.dll) dentro del proyecto. ¿Por eso estoy sorprendido?

  • Sé que System.Web.Extensions fue marcado como obsoleto en 3.5
Author: Prisoner ZERO, 2011-08-09

12 answers

Compruebe si ha incluido la versión.net 4 de System.Web.Extensions - también hay una versión 3.5, pero no creo que funcione.

Estos pasos funcionan para mí:

  1. Crear una nueva aplicación de consola
  2. Cambie el destino a. net 4 en lugar de Client Profile
  3. Añadir una referencia a System.Web.Extensions (4.0)
  4. Tener acceso a JavaScriptSerializer en el Programa.cs now: -)
 459
Author: Steffen,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-09-19 17:58:00
  1. Haga clic derecho en References y haga Add Reference, luego desde Assemblies->Framework seleccione System.Web.Extensions.
  2. Ahora debería poder agregar lo siguiente a su archivo de clase:
    using System.Web.Script.Serialization;
 97
Author: Scott Johnson,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-03-13 16:44:23

Desde el primer resultado de búsqueda en Google:

Http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx

JavaScriptSerializer Class

Proporciona funcionalidad de serialización y deserialización para aplicaciones habilitadas para AJAX.

Jerarquía de herencia

Sistema.Objeto

Sistema.Web.Script.Serialización.JavaScriptSerializer

Espacio de nombres: Sistema.Web.Script.Serialización

Montaje: Sistema.Web.Extensiones (en Sistema.Web.Ampliación.dll)

Por lo tanto, incluya System.Web.Extensions.dll como referencia.

 40
Author: Paul,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-09-11 13:56:03

Estoy usando Visual Studio 2015 y finalmente me encontré con este post.

Sí para utilizar

JavaScriptSerializer json = new JavaScriptSerializer();

Debe hacer clic derecho en referencias y debajo de Ensamblajes choose> Framework choose

System.Web.Extensions

Luego agregue su referencia

using System.Web.Script.Serialization;
 18
Author: Tom Stickel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-17 00:44:14

Esta es la forma de obtener JavaScriptSerializer disponible en su aplicación, targetting .NET 4.0 (full)

using System.Web.Script.Serialization;

Esto debería permitirle crear un nuevo objeto JavaScriptSerializer!

 15
Author: Alex Hopkins,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-09-26 17:24:21

¿Está apuntando al framework. NET 4 o al Perfil de cliente. NET 4?

Si estás apuntando a este último, no encontrarás esa clase. También es posible que le falte una referencia, probablemente a una dll de extensiones.

 10
Author: Christopher Currens,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-09 18:18:45

Para aquellos que parecen estar siguiendo las respuestas anteriores, pero todavía tienen el problema (por ejemplo, ver el primer comentario sobre la pregunta del póster):

Probablemente esté trabajando en una solución con muchos proyectos. El proyecto en el que parece estar trabajando hace referencia a otros proyectos, pero en realidad está modificando un archivo de uno de los otros proyectos. Por ejemplo:

  • referencias del proyecto A System.Web.Extensions
  • proyecto A referencias proyecto B

Pero si el archivo es modificar para usar System.Web.Script.Serialization está en el proyecto B, entonces necesitará agregar una referencia a System.Web.Extension en el proyecto B también.

 9
Author: jltrem,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-05-02 22:58:15
using System.Web.Script.Serialization; 

Está en assembly: System.Web.Extensiones (Sistema.Web.Ampliación.dll)

 9
Author: Ema.H,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-02-07 13:25:53

¿Has incluido una referencia a System.Web.Extensions? Si hace clic en su primer enlace, dice en qué ensamblaje está.

 8
Author: Davy8,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-08-09 18:18:59

Hay que añadir la referencia al proyecto.

En las Asambleas, hay un Sistema.Web.Las extensiones Añaden eso.

Una vez hecho esto pon:

    using System.Web;
    using System.Web.Script;
    using System.Web.Script.Serialization;

Eso funcionó para mí.

 5
Author: riahc3,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-02-21 15:51:15

Para que lo sepas, estoy usando Visual Studio 2013 y he tenido el mismo problema hasta que usé las Propiedades del proyecto para cambiar a 3.5 framework y volver a 4.5. Esto por alguna razón registrado el .dll correctamente y podría usar el Sistema .Web.Extensiones.

introduzca la descripción de la imagen aquí

introduzca la descripción de la imagen aquí

 3
Author: Milan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-10-29 22:42:42

Puede usar otra opción que es la NewtonsoftJASON, puede instalarla desde el Administrador de paquetes NuGet.Herramientas >> Nuget PacakgeManager

introduzca la descripción de la imagen aquí

 2
Author: Alexander Zaldostanov,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-06-16 14:18:22