DataContractJsonSerializer.WriteObject Method

Definition

Serializes an object to a JavaScript Object Notation (JSON) document.

Overloads

WriteObject(Stream, Object)

Serializes a specified object to JavaScript Object Notation (JSON) data and writes the resulting JSON to a stream.

WriteObject(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.

WriteObject(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.

WriteObject(Stream, Object)

Source:
DataContractJsonSerializer.cs
Source:
DataContractJsonSerializer.cs
Source:
DataContractJsonSerializer.cs

Serializes a specified object to JavaScript Object Notation (JSON) data and writes the resulting JSON to a stream.

C#
public void WriteObject(System.IO.Stream stream, object graph);
C#
public override void WriteObject(System.IO.Stream stream, object? graph);
C#
public override void WriteObject(System.IO.Stream stream, object graph);

Parameters

stream
Stream

The Stream that is written to.

graph
Object

The object that contains the data to write to the stream.

Exceptions

The type being serialized does not conform to data contract rules. For example, the DataContractAttribute attribute has not been applied to the type.

There is a problem with the instance being written.

The maximum number of objects to serialize has been exceeded. Check the MaxItemsInObjectGraph property.

Applies to

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1
UWP 10.0

WriteObject(XmlDictionaryWriter, Object)

Source:
DataContractJsonSerializer.cs
Source:
DataContractJsonSerializer.cs
Source:
DataContractJsonSerializer.cs

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.

C#
public override void WriteObject(System.Xml.XmlDictionaryWriter writer, object? graph);
C#
public override void WriteObject(System.Xml.XmlDictionaryWriter writer, object graph);

Parameters

writer
XmlDictionaryWriter

The XmlDictionaryWriter used to write the XML document or stream to map to JSON.

graph
Object

The object that contains the data to write.

Exceptions

The type being serialized does not conform to data contract rules. For example, the DataContractAttribute attribute has not been applied to the type.

There is a problem with the instance being written.

The maximum number of objects to serialize has been exceeded. Check the MaxItemsInObjectGraph property.

Applies to

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

WriteObject(XmlWriter, Object)

Source:
DataContractJsonSerializer.cs
Source:
DataContractJsonSerializer.cs
Source:
DataContractJsonSerializer.cs

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.

C#
public override void WriteObject(System.Xml.XmlWriter writer, object? graph);
C#
public override void WriteObject(System.Xml.XmlWriter writer, object graph);

Parameters

writer
XmlWriter

The XmlWriter used to write the XML document to map to JSON.

graph
Object

The object that contains the data to write.

Exceptions

The type being serialized does not conform to data contract rules. For example, the DataContractAttribute attribute has not been applied to the type.

There is a problem with the instance being written.

The maximum number of objects to serialize has been exceeded. Check the MaxItemsInObjectGraph property.

Applies to

.NET 10 a ďalšie verzie
Produkt Verzie
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1