26

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:

  • Namespace: System.Json
  • Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)

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)

Darbio
  • 11,286
  • 12
  • 60
  • 100
Cotten
  • 8,787
  • 17
  • 61
  • 98

5 Answers5

40

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

slamsal
  • 610
  • 9
  • 13
  • 2
    Using the exact version number worked for me.... Think I read somewhere that System.Json isn't production ready yet so you have to specify version number. – Rojuinex Mar 04 '15 at 20:24
  • 1
    I am building Web API with `dnxcore50` and `Visual Studio Code`. I cannot get `JsonObject` to resolve. What is the way to install it using `dnu install`. Or there is another way to do it? I tried both `System.Json` and `System.JsonObject` but in both cases I got `the type or namaespace name 'JsonObject' does not exist in the namespace 'System'...` All I need is to return a Json object from an `async Task` method using HttpClient. How can I resolve this? If `JsonObject` is not the right thing to serve my purpose then what should I use as an alternative? – Subrata Sarkar Dec 14 '15 at 13:50
  • Anybody knows what to do in case Project > Manage Nuget Packages shows `System.Text.Json` as installed but visual studio still complains `The type or namespace name Json` does not exist in namespace System.Text... ? (Version System.Text.Json : 4.7.2 , Visual studio : 16.6.2, NuGetPackage Manager: 5.6.0 , Visual Studio: 16.6.2 , Microsoft .NET Framework Version 4.8.03752) – Rose Oct 20 '20 at 01:53
7

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?

Community
  • 1
  • 1
Darbio
  • 11,286
  • 12
  • 60
  • 100
  • the assembly referenced there is for Silverlight (..Silverlight\v4.0\System.ServiceModel.Web.dll). I tried adding System.ServiceModel.Web for .NET but it had no effect. – Cotten Oct 12 '12 at 13:05
  • Is your target framework 4.5? Full or client (if 4.5 has client?) – Darbio Oct 12 '12 at 13:07
  • System.Json is still in beta and so Nuget package seems to be the way to get it. It is not built-in the most recent full Framework V 4.5.1. Personally I like Json.Net's API which is much less verbose and faster than Windows.Data.Json or System.Json. See http://james.newtonking.com/json/help/html/JsonNetVsWindowsDataJson.htm – Shital Shah Jan 14 '14 at 22:49
3

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

balaji palamadai
  • 629
  • 2
  • 8
  • 26
0

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/

  • 1
    Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Nov 25 '15 at 12:02
  • @kleopatra , Hi, answer is edited. Please check and give upvote. :) – Md Kauser Ahmmed Nov 25 '15 at 12:20
-3

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.