在 .Net 4.0 中找不到 JavaScriptSerializer
是的,我已经在项目中包含了 System.Web.Extensions(在 System.Web.Extensions.dll 中)。这就是为什么我感到震惊?
- 我确实知道
System.Web.Extensions
被标记为 在 3.5 中已过时
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
检查是否包含 .net 4 版本的
System.Web.Extensions
- 还有一个 3.5 版本,但我认为该版本不起作用。这些步骤对我有用:
System.Web.Extensions
(4.0) 的引用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:
System.Web.Extensions
(4.0)JavaScriptSerializer
in Program.cs now :-)References
并执行Add Reference
,然后从Assemblies->Framework
中选择System.Web.Extensions
。References
and doAdd Reference
, then fromAssemblies->Framework
selectSystem.Web.Extensions
.从谷歌上的第一个搜索结果:
http:// /msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
因此,包括
System .Web.Extensions.dll
作为参考。From the first search result on google:
http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
So, include
System.Web.Extensions.dll
as a reference.我正在使用 Visual Studio 2015,最后看到了这篇文章。
是的,为了使用
您必须右键单击引用并在程序集下 -->框架选择
然后添加您的参考
I'm using Visual Studio 2015 and finally ran across this post.
Yes in order to use
You must right click on references and under Assemblies --> Framework choose
Then add in your reference
这是如何在您的应用程序中使用 JavaScriptSerializer,目标是
.NET 4.0
(完整)这应该允许您创建一个新的
JavaScriptSerializer
对象!This is how to get JavaScriptSerializer available in your application, targetting
.NET 4.0
(full)This should allow you to create a new
JavaScriptSerializer
object!正在汇编中:System.Web.Extensions (System.Web.Extensions.dll)
is in assembly : System.Web.Extensions (System.Web.Extensions.dll)
您的目标是 .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.
对于那些似乎遵循上述答案但仍然存在问题的人(例如,请参阅对发帖者问题的第一条评论):
您可能正在使用包含许多项目的解决方案。您似乎正在工作的项目引用了其他项目,但实际上您正在修改其他项目之一的文件。例如:
但如果您要修改以使用 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:
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 toSystem.Web.Extension
in project B as well.您是否包含对 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.您必须添加对项目的引用。
在Assemblies中,有一个System.Web.Extensions添加。
完成后:
这对我有用。
You have to add the reference to the project.
In Assemblies, there is a System.Web.Extensions Add that.
Once that is done put:
That worked for me.
您可以使用另一个选项,即 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...
如您所知,我使用的是 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.