命名空间System中不存在Json

Cot*_*ten 18 json .net-4.5 asp.net-web-api

在本教程中:http://www.asp.net/web-api/videos/getting-started/custom-validation Jon使用

dynamic error = new JsonObject();
Run Code Online (Sandbox Code Playgroud)

using System.Json;
Run Code Online (Sandbox Code Playgroud)

我猜这是JsonObject:http : //msdn.microsoft.com/en-us/library/system.json.jsonobject( v=vs.110) .aspx位于:

  • 命名空间:System.Json
  • 程序集:System.Runtime.Serialization(在System.Runtime.Serialization.dll中)

我已经添加了System.Runtime.Serialization引用但仍无法找到System.Json.

我读微软的文档错了吗?(我使用的是.NET 4.5)

sla*_*sal 33

试试这个:

PM> Install-Package System.Json -Version 4.0.20126.16343
Run Code Online (Sandbox Code Playgroud)

Per:http://nuget.org/packages/System.Json

有效!

如果您对如何添加输入nuget代码有疑问,请点击以下链接:http://docs.nuget.org/docs/start-here/using-the-package-manager-console

  • 使用确切的版本号为我工作....想想我在某处看到System.Json还没有生产就绪,所以你必须指定版本号. (2认同)

Dar*_*bio 7

http://www.webcosmoforums.com/asp/32551-type-namespace-name-json-does-not-exist-namespace-system-runtime-serialization.html

很可能您缺少对System.ServiceModel.Web的引用

确保您的应用程序以项目属性中的.Net 4.5框架为目标.

System.Json对象仅在4.5中可用

编辑:

使用Nuget安装system.json:'Install-Package System.Json'

如何在没有JSON.NET库的情况下解析JSON?