命名空间 System 中不存在 Json
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12859319/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Json does not exist in the namespace System
提问by Cotten
In this tutorial: http://www.asp.net/web-api/videos/getting-started/custom-validationJon uses
在本教程中:http: //www.asp.net/web-api/videos/getting-started/custom-validationJon 使用
dynamic error = new JsonObject();
with
和
using System.Json;
I guess it's the JsonObject here: http://msdn.microsoft.com/en-us/library/system.json.jsonobject(v=vs.110).aspxlocated in:
我猜它是这里的 JsonObject:http: //msdn.microsoft.com/en-us/library/system.json.jsonobject(v=vs.110) .aspx位于:
- Namespace: System.Json
- Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
- 命名空间:System.Json
- 程序集:System.Runtime.Serialization(在 System.Runtime.Serialization.dll 中)
I've added System.Runtime.Serialization a reference but still cannot find System.Json.
我已经添加了 System.Runtime.Serialization 一个参考,但仍然找不到 System.Json。
Am I reading the Microsoft docs wrong? (I'm using .NET 4.5)
我读错了 Microsoft 文档吗?(我正在使用 .NET 4.5)
回答by slamsal
Try this:
尝试这个:
PM> Install-Package System.Json -Version 4.0.20126.16343
Per: http://nuget.org/packages/System.Json
每个:http: //nuget.org/packages/System.Json
It worked!
有效!
If you have questions on how to add enter nuget code, please follow the link below: http://docs.nuget.org/docs/start-here/using-the-package-manager-console
如果您对如何添加输入 nuget 代码有疑问,请点击以下链接:http://docs.nuget.org/docs/start-here/using-the-package-manager-console
回答by Darbio
Most likely you are missing a reference to System.ServiceModel.Web
您很可能缺少对 System.ServiceModel.Web 的引用
Make sure your application is targeting the .Net 4.5 framework in the project properties.
确保您的应用程序在项目属性中面向 .Net 4.5 框架。
The System.Json objects are only available in 4.5
System.Json 对象仅在 4.5 中可用
Edit:
编辑:
Use Nuget to install system.json : 'Install-Package System.Json'
使用 Nuget 安装 system.json : 'Install-Package System.Json'
回答by balaji palamadai
The Json object works only from Controller class and not outside. Even if we refer System.Web.MVC outside controller, we have access only to JsonResult and not to Json as Json object is protected object of JsonResult. Please refer the below documentation which explains that,
Json 对象仅适用于 Controller 类,而不适用于外部。即使我们在控制器外部引用 System.Web.MVC,我们也只能访问 JsonResult 而不能访问 Json,因为 Json 对象是 JsonResult 的受保护对象。请参阅以下文档,其中解释了这一点,
http://msdn.microsoft.com/en-us/library/dd504936(v=vs.118).aspx
http://msdn.microsoft.com/en-us/library/dd504936(v=vs.118).aspx
回答by Md Kauser Ahmmed
If you want to use other .Net json serializer, you can use the following:
如果要使用其他 .Net json 序列化程序,可以使用以下命令:
- go to manage nuget package.
- search json.net.
- click install.
- 去管理nuget包。
- 搜索 json.net。
- 点击安装。
for more details, follow - http://netfx.codeplex.com/
有关更多详细信息,请关注 - http://netfx.codeplex.com/
回答by Md Kauser Ahmmed
Using System.json will not work for .Net 4 framework. The library is deprecated. To check it try:
使用 System.json 不适用于 .Net 4 框架。该库已弃用。要检查它,请尝试:
- Go Add reference... to project.
- On .Net Tab, Search System.json, you will not find any.
- 去添加引用...到项目。
- 在 .Net 选项卡上,搜索 System.json,您将找不到任何内容。
That means, it is deprecated.
这意味着,它已被弃用。

