1 out of 7 rated this helpful - Rate this topic

System.Json Namespace

The System.Json namespace provides standards-based support for the serialization of JavaScript Object Notation (JSON).

JSON is a lightweight, text-based data interchange format that is used to serialize structured data for transmission over networks. It has three primitive data types: string, number, and Boolean. It has two data structures: array and object. An array is an ordered collection of values, where the value can be a JSON primitive, object or array. An object is an unordered set of key/value pairs. The key is a string and the value, as with the array, can be a JSON primitive, object, or array.

In this documentation, the serialized textual representation of JSON is referred to as “text-based JSON” to distinguish it from the deserialized representation of JSON as a Common Language Runtime (CLR) type, which is referred to here as a “JSON CLR type” or as a “JSON CLR object” if we are referring to an instance of the type.

JSON CLR types represent the three text-based JSON primitives with the JsonPrimitive type. The JsonType() property indicates which primitive is contained in the type instance: String, Number, or Boolean.

JSON CLR types represent the two text-based structured types with JsonArray and JsonObject. A JsonArray is an ordered sequence of zero or more JsonValue objects. A JsonValue is the JSON CLR representation of a JSON text-based value, which can be either a primitive or structured type. A JsonObject is an unordered collection of zero or more String/JsonValue pairs, which represent the key/value pairs of the text-based JSON object.

  Class Description
Public class JsonArray A JsonArray is an ordered sequence of zero or more JsonValue objects.
Public class JsonObject A JsonObject is an unordered collection of zero or more key/value pairs.
Public class JsonPrimitive Represents a JavaScript Object Notation (JSON) primitive type in the common language runtime (CLR).
Public class JsonValue This is the abstract base class for JavaScript Object Notation (JSON) common language runtime (CLR) types.
  Enumeration Description
Public enumeration JsonType An enumeration that specifies primitive and structured JavaScript Object Notation (JSON) common language runtime (CLR) types.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Simple getting started example
Took me a while to figure this out, so thought I'd add it for others:

A simple use case is as follows:
var json = JsonValue.Parse(@"{""simple"":""value1"",""complex"":{""name"":""value2"",""id"":""value3""}}";

string simpleValue = json["simple"]; // contains "value1"
var complex = json["complex"];
string nameValue = complex["name"] // contains "value2"

Check out the expansion of these classes in the WCF Web Apis work

A lot of great work is being done to optimize Json serialization and deserialization in this codeplex project:


http://wcf.codeplex.com/http://wcf.codeplex.comhttp://wcf.codeplex.comhttp://wcf.codeplex.com/

Specifically, check this page out:

http://wcf.codeplex.com/wikipage?title=JsonValue

And check out the samples that are part of this download:


http://wcf.codeplex.com/releases/view/64396http://wcf.codeplex.com/releases/view/64396


Its not wrong ...
The doc is actually correct - this namespace is targeted at Silverlight runtime - not standard 3.5 or 4.0 .NET runtimes
This page is wrong
There is no System.Json name space in either .net 3.5 or 4.0.
In 3.5, reference System.ServiceModel.Web and find Json in System.Runtime.Serialization.Json; works for VS 2008.
In .net 4.0 and VS 2010, reference System.Runtime.Serialization and find Json in System.Runtime.Serialization.Json.
Use JsonReaderWriterFactory to create a writer and/or writer.