在 .Net 4.0 中找不到 JavaScriptSerializer

发布于 2024-11-28 20:55:38 字数 578 浏览 1 评论 0原文

我似乎找不到 JavaScriptSerializer 对象也不是 Visual Studio 2010 中的 System.Web.Script.Serialization 命名空间。我需要将某些内容序列化为 JSON 我应该使用什么?

是的,我已经在项目中包含了 System.Web.Extensions(在 System.Web.Extensions.dll 中)。这就是为什么我感到震惊?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

心凉怎暖 2024-12-05 20:55:38

检查是否包含 .net 4 版本的 System.Web.Extensions - 还有一个 3.5 版本,但我认为该版本不起作用。

这些步骤对我有用:

  1. 创建一个新的控制台应用程序
  2. 将目标更改为 .net 4 而不是 Client Profile
  3. 添加对 System.Web.Extensions (4.0) 的引用
  4. 有权访问 JavaScriptSerializer :-)

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 :-)
饮湿 2024-12-05 20:55:38
  1. 右键单击References并执行Add Reference,然后从Assemblies->Framework中选择System.Web.Extensions
  2. 现在您应该能够将以下内容添加到您的类文件中:
    using System.Web.Script.Serialization;
  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;
凶凌 2024-12-05 20:55:38

从谷歌上的第一个搜索结果:

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

JavaScriptSerializer类

为支持 AJAX 的应用程序提供序列化和反序列化功能。

继承层次

系统对象

System.Web.Script.Serialization.JavaScriptSerializer

命名空间:System.Web.Script.Serialization

程序集:System.Web.Extensions(在 System.Web.Extensions.dll 中)

因此,包括 System .Web.Extensions.dll 作为参考。

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.

〆凄凉。 2024-12-05 20:55:38

我正在使用 Visual Studio 2015,最后看到了这篇文章。

是的,为了使用

JavaScriptSerializer json = new JavaScriptSerializer();

您必须右键单击引用并在程序集下 -->框架选择

System.Web.Extensions

然后添加您的参考

using System.Web.Script.Serialization;

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;
倾城花音 2024-12-05 20:55:38

这是如何在您的应用程序中使用 JavaScriptSerializer,目标是 .NET 4.0(完整)

using System.Web.Script.Serialization;

这应该允许您创建一个新的 JavaScriptSerializer 对象!

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!

剧终人散尽 2024-12-05 20:55:38
using System.Web.Script.Serialization; 

正在汇编中:System.Web.Extensions (System.Web.Extensions.dll)

using System.Web.Script.Serialization; 

is in assembly : System.Web.Extensions (System.Web.Extensions.dll)

呆萌少年 2024-12-05 20:55:38

您的目标是 .NET 4 框架还是 .NET 4 Client Profile?

如果您的目标是后者,您将找不到该课程。您还可能缺少引用,可能是扩展 dll 的引用。

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.

—━☆沉默づ 2024-12-05 20:55:38

对于那些似乎遵循上述答案但仍然存在问题的人(例如,请参阅对发帖者问题的第一条评论):

您可能正在使用包含许多项目的解决方案。您似乎正在工作的项目引用了其他项目,但实际上您正在修改其他项目之一的文件。例如:

  • 项目 A 引用 System.Web.Extensions
  • 项目 A 引用项目 B

但如果您要修改以使用 System.Web.Script.Serialization 的文件位于项目 B 中,那么您还需要在项目 B 中添加对 System.Web.Extension 的引用。

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:

  • project A references System.Web.Extensions
  • project A references project B

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.

允世 2024-12-05 20:55:38

您是否包含对 System.Web.Extensions 的引用?如果您单击第一个链接,它会显示它所在的程序集。

Did you include a reference to System.Web.Extensions? If you click on your first link it says which assembly it's in.

笑咖 2024-12-05 20:55:38

您必须添加对项目的引用。

在Assemblies中,有一个System.Web.Extensions添加。

完成后:

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

这对我有用。

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.

恰似旧人归 2024-12-05 20:55:38

您可以使用另一个选项,即 Newtonsoft.Json,您可以从 NuGet 包管理器安装它。

工具>> Nuget 包管理器>>包管理器控制台,通过发出命令

Install-Package Newtonsoft.Json

使用 GUI 工具>>> Nuget 包管理器>>管理解决方案的 NuGet 包...

在此处输入图像描述

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...

enter image description here

ι不睡觉的鱼゛ 2024-12-05 20:55:38

如您所知,我使用的是 Visual Studio 2013,并且遇到了同样的问题,直到我使用项目属性切换到 3.5 框架并返回到 4.5。由于某种原因,这正确注册了 .dll,我可以使用 System.Web.Extensions

输入图片此处描述

在此处输入图像描述

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.

enter image description here

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文