Cotten
Cotten

Reputation: 9077

Json does not exist in the namespace System

In this tutorial: http://www.asp.net/web-api/videos/getting-started/custom-validation Jon uses

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).aspx located in:

I've added System.Runtime.Serialization a reference but still cannot find System.Json.

Am I reading the Microsoft docs wrong? (I'm using .NET 4.5)

Upvotes: 27

Views: 89043

Answers (5)

Md Kauser Ahmmed
Md Kauser Ahmmed

Reputation: 309

Using System.json will not work for .Net 4 framework. The library is deprecated. To check it try:

  1. Go Add reference... to project.
  2. On .Net Tab, Search System.json, you will not find any.

That means, it is deprecated.

Upvotes: -4

Md Kauser Ahmmed
Md Kauser Ahmmed

Reputation: 309

If you want to use other .Net json serializer, you can use the following:

  1. go to manage nuget package.
  2. search json.net.
  3. click install.

for more details, follow - http://netfx.codeplex.com/

Upvotes: 0

balaji palamadai
balaji palamadai

Reputation: 629

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,

http://msdn.microsoft.com/en-us/library/dd504936(v=vs.118).aspx

Upvotes: 3

slamsal
slamsal

Reputation: 620

Try this:

PM> Install-Package System.Json -Version 4.0.20126.16343

Per: 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

Upvotes: 41

Darbio
Darbio

Reputation: 11418

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

Most likely you are missing a reference to System.ServiceModel.Web

Make sure your application is targeting the .Net 4.5 framework in the project properties.

The System.Json objects are only available in 4.5

Edit:

Use Nuget to install system.json : 'Install-Package System.Json'

How to parse JSON without JSON.NET library?

Upvotes: 7

Related Questions