Export (0) Print
Expand All

DataContractJsonSerializer Class

Serializes objects to the JavaScript Object Notation (JSON) and deserializes JSON data to objects. This class cannot be inherited.

System.Object
  System.Runtime.Serialization.XmlObjectSerializer
    System.Runtime.Serialization.Json.DataContractJsonSerializer

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

public sealed class DataContractJsonSerializer : XmlObjectSerializer

The DataContractJsonSerializer type exposes the following members.

  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsDataContractJsonSerializer(Type)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsDataContractJsonSerializer(Type, IEnumerable<Type>)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type, with a collection of known types that may be present in the object graph.
Public methodSupported in .NET for Windows Store appsDataContractJsonSerializer(Type, DataContractJsonSerializerSettings)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type and serializer settings.
Public methodDataContractJsonSerializer(Type, String)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of a specified type using the XML root element specified by a parameter.
Public methodDataContractJsonSerializer(Type, XmlDictionaryString)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of a specified type using the XML root element specified by a parameter of type XmlDictionaryString.
Public methodDataContractJsonSerializer(Type, String, IEnumerable<Type>)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of a specified type using the XML root element specified by a parameter, with a collection of known types that may be present in the object graph.
Public methodDataContractJsonSerializer(Type, XmlDictionaryString, IEnumerable<Type>)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of a specified type using the XML root element specified by a parameter of type XmlDictionaryString, with a collection of known types that may be present in the object graph.
Public methodDataContractJsonSerializer(Type, IEnumerable<Type>, Int32, Boolean, IDataContractSurrogate, Boolean)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type. This method also specifies a list of known types that may be present in the object graph, the maximum number of graph items to serialize or deserialize, whether to ignore unexpected data or emit type information, and a surrogate for custom serialization.
Public methodDataContractJsonSerializer(Type, String, IEnumerable<Type>, Int32, Boolean, IDataContractSurrogate, Boolean)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type. This method also specifies the root name of the XML element, a list of known types that may be present in the object graph, the maximum number of graph items to serialize or deserialize, whether to ignore unexpected data or emit type information, and a surrogate for custom serialization.
Public methodDataContractJsonSerializer(Type, XmlDictionaryString, IEnumerable<Type>, Int32, Boolean, IDataContractSurrogate, Boolean)Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type. This method also specifies the root name of the XML element, a list of known types that may be present in the object graph, the maximum number of graph items to serialize or deserialize, whether to ignore unexpected data or emit type information, and a surrogate for custom serialization.
Top

  NameDescription
Public propertyDataContractSurrogateGets a surrogate type that is currently active for a given IDataContractSurrogate instance. Surrogates can extend the serialization or deserialization process.
Public propertySupported in .NET for Windows Store appsDateTimeFormatGets the format of the date and time type items in object graph.
Public propertySupported in .NET for Windows Store appsEmitTypeInformationGets or sets the data contract JSON serializer settings to emit type information.
Public propertyIgnoreExtensionDataObjectGets a value that specifies whether unknown data is ignored on deserialization and whether the IExtensibleDataObject interface is ignored on serialization.
Public propertySupported by Portable Class LibrarySupported in .NET for Windows Store appsKnownTypesGets a collection of types that may be present in the object graph serialized using this instance of the DataContractJsonSerializer.
Public propertyMaxItemsInObjectGraphGets the maximum number of items in an object graph that the serializer serializes or deserializes in one read or write call.
Public propertySupported in .NET for Windows Store appsSerializeReadOnlyTypesGets or sets a value that specifies whether to serialize read only types.
Public propertySupported in .NET for Windows Store appsUseSimpleDictionaryFormatGets or sets a value that specifies whether to use a simple dictionary format.
Top

  NameDescription
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsStartObject(XmlDictionaryReader)Gets a value that specifies whether the XmlDictionaryReader is positioned over an XML element that represents an object the serializer can deserialize from. (Overrides XmlObjectSerializer.IsStartObject(XmlDictionaryReader).)
Public methodIsStartObject(XmlReader)Determines whether the XmlReader is positioned on an object that can be deserialized. (Overrides XmlObjectSerializer.IsStartObject(XmlReader).)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadObject(Stream)Reads a document stream in the JSON (JavaScript Object Notation) format and returns the deserialized object. (Overrides XmlObjectSerializer.ReadObject(Stream).)
Public methodReadObject(XmlDictionaryReader)Reads the XML document mapped from JSON (JavaScript Object Notation) with an XmlDictionaryReader and returns the deserialized object. (Overrides XmlObjectSerializer.ReadObject(XmlDictionaryReader).)
Public methodReadObject(XmlReader)Reads the XML document mapped from JSON (JavaScript Object Notation) with an XmlReader and returns the deserialized object. (Overrides XmlObjectSerializer.ReadObject(XmlReader).)
Public methodReadObject(XmlDictionaryReader, Boolean)Reads the XML document mapped from JSON with an XmlDictionaryReader and returns the deserialized object; it also enables you to specify whether the serializer should verify that it is positioned on an appropriate element before attempting to deserialize. (Overrides XmlObjectSerializer.ReadObject(XmlDictionaryReader, Boolean).)
Public methodReadObject(XmlReader, Boolean)Reads an XML document mapped from JSON with an XmlReader and returns the deserialized object; it also enables you to specify whether the serializer should verify that it is positioned on an appropriate element before attempting to deserialize. (Overrides XmlObjectSerializer.ReadObject(XmlReader, Boolean).)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodWriteEndObject(XmlDictionaryWriter)Writes the closing XML element to an XML document, using an XmlDictionaryWriter, which can be mapped to JavaScript Object Notation (JSON). (Overrides XmlObjectSerializer.WriteEndObject(XmlDictionaryWriter).)
Public methodWriteEndObject(XmlWriter)Writes the closing XML element to an XML document, using an XmlWriter, which can be mapped to JavaScript Object Notation (JSON). (Overrides XmlObjectSerializer.WriteEndObject(XmlWriter).)
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsWriteObject(Stream, Object)Serializes a specified object to JavaScript Object Notation (JSON) data and writes the resulting JSON to a stream. (Overrides XmlObjectSerializer.WriteObject(Stream, Object).)
Public methodWriteObject(XmlDictionaryWriter, Object)Serializes an object to XML that may be mapped to JavaScript Object Notation (JSON). Writes all the object data, including the starting XML element, content, and closing element, with an XmlDictionaryWriter. (Overrides XmlObjectSerializer.WriteObject(XmlDictionaryWriter, Object).)
Public methodWriteObject(XmlWriter, Object)Serializes an object to XML that may be mapped to JavaScript Object Notation (JSON). Writes all the object data, including the starting XML element, content, and closing element, with an XmlWriter. (Overrides XmlObjectSerializer.WriteObject(XmlWriter, Object).)
Public methodWriteObjectContent(XmlDictionaryWriter, Object)Writes the XML content that can be mapped to JavaScript Object Notation (JSON) using an XmlDictionaryWriter. (Overrides XmlObjectSerializer.WriteObjectContent(XmlDictionaryWriter, Object).)
Public methodWriteObjectContent(XmlWriter, Object)Writes the XML content that can be mapped to JavaScript Object Notation (JSON) using an XmlWriter. (Overrides XmlObjectSerializer.WriteObjectContent(XmlWriter, Object).)
Public methodWriteStartObject(XmlDictionaryWriter, Object)Writes the opening XML element for serializing an object to XML that can be mapped to JavaScript Object Notation (JSON) using an XmlDictionaryWriter. (Overrides XmlObjectSerializer.WriteStartObject(XmlDictionaryWriter, Object).)
Public methodWriteStartObject(XmlWriter, Object)Writes the opening XML element for serializing an object to XML that can be mapped to JavaScript Object Notation (JSON) using an XmlWriter. (Overrides XmlObjectSerializer.WriteStartObject(XmlWriter, Object).)
Top

Use the DataContractJsonSerializer class to serialize instances of a type into a JSON document and to deserialize a JSON document into an instance of a type. For example, you can create a type named Person with properties that contain essential data, such as a name and address. You can then create and manipulate an instance of the Person class and write all of its property values in a JSON document for later retrieval. This JSON document can later be deserialized into the Person class or another class with an equivalent data contract.

If an error occurs during the serialization of an outgoing reply on the server or the reply operation throws an exception for some other reason, it may not get returned to the client as a fault.

.NET Framework

Supported in: 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft