DataContractJsonSerializer 類別

定義

將物件序列化為 JavaScript 物件標記法 (JSON) 以及將 JSON 資料還原序列化為物件。Serializes objects to the JavaScript Object Notation (JSON) and deserializes JSON data to objects. 此類別無法獲得繼承。This class cannot be inherited.

public ref class DataContractJsonSerializer sealed
public ref class DataContractJsonSerializer sealed : System::Runtime::Serialization::XmlObjectSerializer
public sealed class DataContractJsonSerializer
public sealed class DataContractJsonSerializer : System.Runtime.Serialization.XmlObjectSerializer
type DataContractJsonSerializer = class
type DataContractJsonSerializer = class
    inherit XmlObjectSerializer
Public NotInheritable Class DataContractJsonSerializer
Public NotInheritable Class DataContractJsonSerializer
Inherits XmlObjectSerializer
繼承
DataContractJsonSerializer
繼承
DataContractJsonSerializer

備註

對於涉及序列化至 JSON 並從 JSON 還原序列化的大部分案例,我們建議在 命名空間的 System.Text.Js中的 apiFor most scenarios that involve serializing to JSON and deserializing from JSON, we recommend the APIs in the System.Text.Json namespace.

如果您的案例需要 DataContractJsonSerializer 類別,您可以使用它來將型別的實例序列化為 JSON 檔,並將 JSON 檔案還原序列化為類型的實例。If your scenario requires the DataContractJsonSerializer class, you can use it to serialize instances of a type into a JSON document and to deserialize a JSON document into an instance of a type. 例如,您可以使用包含基本資料的屬性 (例如姓名和地址) 來建立名為 Person 的型別。For example, you can create a type named Person with properties that contain essential data, such as a name and address. 然後您可以建立及操作 Person 類別的執行個體,並將所有的屬性值寫入 JSON 文件中以供日後擷取。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. JSON 文件可以在日後使用對等的資料合約還原序列化為 Person 類別或其他類別。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.

建構函式

DataContractJsonSerializer(Type)

初始化 DataContractJsonSerializer 類別的新執行個體,以序列化或還原序列化所指定型別的物件。Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type.

DataContractJsonSerializer(Type, DataContractJsonSerializerSettings)

初始化 DataContractJsonSerializer 類別的新執行個體,以序列化或還原序列化所指定型別及序列化程式設定的物件。Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type and serializer settings.

DataContractJsonSerializer(Type, IEnumerable<Type>)

初始化 DataContractJsonSerializer 類別的新執行個體,以序列化或還原序列化所指定型別的物件,以及可能存在物件圖形中的已知型別集合。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.

DataContractJsonSerializer(Type, IEnumerable<Type>, Int32, Boolean, IDataContractSurrogate, Boolean)

初始化 DataContractJsonSerializer 類別的新執行個體,以序列化或還原序列化所指定型別的物件。Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type. 這個方法也會指定可能存在物件圖形中之已知型別的清單、要序列化或還原序列化之圖形項目的最大數、是否要忽略未預期資料或發出型別資訊,以及自訂序列化的 Surrogate。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.

DataContractJsonSerializer(Type, String)

初始化 DataContractJsonSerializer 類別的新執行個體,使用參數所指定的 XML 根項目來序列化或還原序列化指定型別的物件。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.

DataContractJsonSerializer(Type, String, IEnumerable<Type>)

初始化 DataContractJsonSerializer 類別的新執行個體,使用參數所指定的 XML 根項目來序列化或還原序列化指定型別的物件,以及可能存在物件圖形中的已知型別集合。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.

DataContractJsonSerializer(Type, String, IEnumerable<Type>, Int32, Boolean, IDataContractSurrogate, Boolean)

初始化 DataContractJsonSerializer 類別的新執行個體,以序列化或還原序列化所指定型別的物件。Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type. 這個方法也會指定 XML 項目的根名稱、可能存在物件圖形中之已知型別的清單、要序列化或還原序列化之圖形項目的最大數、是否要忽略未預期資料或發出型別資訊,以及自訂序列化的 Surrogate。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.

DataContractJsonSerializer(Type, XmlDictionaryString)

初始化 DataContractJsonSerializer 類別的新執行個體,使用 XmlDictionaryString 型別之參數所指定的 XML 根項目來序列化或還原序列化指定型別的物件。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.

DataContractJsonSerializer(Type, XmlDictionaryString, IEnumerable<Type>)

初始化 DataContractJsonSerializer 類別的新執行個體,使用 XmlDictionaryString 型別之參數所指定的 XML 根項目來序列化或還原序列化指定型別的物件,以及可能存在物件圖形中的已知型別集合。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.

DataContractJsonSerializer(Type, XmlDictionaryString, IEnumerable<Type>, Int32, Boolean, IDataContractSurrogate, Boolean)

初始化 DataContractJsonSerializer 類別的新執行個體,以序列化或還原序列化所指定型別的物件。Initializes a new instance of the DataContractJsonSerializer class to serialize or deserialize an object of the specified type. 這個方法也會指定 XML 項目的根名稱、可能存在物件圖形中之已知型別的清單、要序列化或還原序列化之圖形項目的最大數、是否要忽略未預期資料或發出型別資訊,以及自訂序列化的 Surrogate。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.

屬性

DataContractSurrogate

取得指定 IDataContractSurrogate 執行個體目前使用的 Surrogate 型別。Gets a surrogate type that is currently active for a given IDataContractSurrogate instance. Surrogate 可以擴充序列化或還原序列化程序。Surrogates can extend the serialization or deserialization process.

DateTimeFormat

取得物件圖形中日期和時間型別項目的格式。Gets the format of the date and time type items in object graph.

EmitTypeInformation

取得或設定要發出型別資訊的資料合約 JSON 序列化程式設定。Gets or sets the data contract JSON serializer settings to emit type information.

IgnoreExtensionDataObject

取得值,這個值會指定還原序列化時是否忽略未知資料,以及序列化時是否忽略 IExtensibleDataObject 介面。Gets a value that specifies whether unknown data is ignored on deserialization and whether the IExtensibleDataObject interface is ignored on serialization.

KnownTypes

取得型別的集合,這些型別可能會存在於使用這個 DataContractJsonSerializer 執行個體所序列化的物件圖形中。Gets a collection of types that may be present in the object graph serialized using this instance of the DataContractJsonSerializer.

MaxItemsInObjectGraph

取得物件圖形中序列化程式在一次讀取或寫入呼叫中,序列化或還原序列化的最大項目數。Gets the maximum number of items in an object graph that the serializer serializes or deserializes in one read or write call.

SerializeReadOnlyTypes

取得或設定值,指定是否要序列化唯讀型別。Gets or sets a value that specifies whether to serialize read only types.

UseSimpleDictionaryFormat

取得值,指定是否要使用簡單的字典格式。Gets a value that specifies whether to use a simple dictionary format.

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
IsStartObject(XmlDictionaryReader)

取得值,這個值會指定 XmlDictionaryReader 是否位於表示序列化程式能夠還原序列化之物件的 XML 項目上。Gets a value that specifies whether the XmlDictionaryReader is positioned over an XML element that represents an object the serializer can deserialize from.

IsStartObject(XmlReader)

判斷 XmlReader 是否置於可還原序列化的物件上。Determines whether the XmlReader is positioned on an object that can be deserialized.

MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ReadObject(Stream)

讀取 JSON (JavaScript 物件標記法) 格式的文件資料流,然後傳回已還原序列化的物件。Reads a document stream in the JSON (JavaScript Object Notation) format and returns the deserialized object.

ReadObject(XmlDictionaryReader)

使用 XmlDictionaryReader 讀取從 JSON (JavaScript 物件標記法) 對應的 XML 文件,然後傳回已還原序列化的物件。Reads the XML document mapped from JSON (JavaScript Object Notation) with an XmlDictionaryReader and returns the deserialized object.

ReadObject(XmlDictionaryReader, Boolean)

使用 XmlDictionaryReader 讀取從 JSON 對應的 XML 文件,然後傳回已還原序列化的物件。它也可以讓您指定序列化程式在嘗試還原序列化前是否檢查位於適當的項目上。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.

ReadObject(XmlReader)

使用 XmlReader 讀取從 JSON (JavaScript 物件標記法) 對應的 XML 文件,然後傳回已還原序列化的物件。Reads the XML document mapped from JSON (JavaScript Object Notation) with an XmlReader and returns the deserialized object.

ReadObject(XmlReader, Boolean)

使用 XmlReader 讀取從 JSON 對應的 XML 文件,然後傳回已還原序列化的物件。它也可以讓您指定序列化程式在嘗試還原序列化前是否檢查位於適當的項目上。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.

ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
WriteEndObject(XmlDictionaryWriter)

使用 XmlDictionaryWriter 將結尾 XML 項目寫入可以對應至 JavaScript 物件標記法 (JSON) 的 XML 文件。Writes the closing XML element to an XML document, using an XmlDictionaryWriter, which can be mapped to JavaScript Object Notation (JSON).

WriteEndObject(XmlWriter)

使用 XmlWriter 將結尾 XML 項目寫入可以對應至 JavaScript 物件標記法 (JSON) 的 XML 文件。Writes the closing XML element to an XML document, using an XmlWriter, which can be mapped to JavaScript Object Notation (JSON).

WriteObject(Stream, Object)

將指定物件序列化為 JavaScript 物件標記法 (JSON) 資料,然後將產生的 JSON 寫入資料流。Serializes a specified object to JavaScript Object Notation (JSON) data and writes the resulting JSON to a stream.

WriteObject(XmlDictionaryWriter, Object)

將物件序列化為可以對應至 JavaScript 物件標記法 (JSON) 的 XML。Serializes an object to XML that may be mapped to JavaScript Object Notation (JSON). 使用 XmlDictionaryWriter 來寫入所有的物件資料,包括起始 XML 項目、內容和結尾項目。Writes all the object data, including the starting XML element, content, and closing element, with an XmlDictionaryWriter.

WriteObject(XmlWriter, Object)

將物件序列化為可以對應至 JavaScript 物件標記法 (JSON) 的 XML。Serializes an object to XML that may be mapped to JavaScript Object Notation (JSON). 使用 XmlWriter 來寫入所有的物件資料,包括起始 XML 項目、內容和結尾項目。Writes all the object data, including the starting XML element, content, and closing element, with an XmlWriter.

WriteObjectContent(XmlDictionaryWriter, Object)

使用 XmlDictionaryWriter 來撰寫可以對應至 JavaScript 物件標記法 (JSON) 的 XML 內容。Writes the XML content that can be mapped to JavaScript Object Notation (JSON) using an XmlDictionaryWriter.

WriteObjectContent(XmlWriter, Object)

使用 XmlWriter 來撰寫可以對應至 JavaScript 物件標記法 (JSON) 的 XML 內容。Writes the XML content that can be mapped to JavaScript Object Notation (JSON) using an XmlWriter.

WriteStartObject(XmlDictionaryWriter, Object)

使用 XmlDictionaryWriter 寫入開頭 XML 項目,將物件序列化為可以對應至 JavaScript 物件標記法 (JSON) 的 XML。Writes the opening XML element for serializing an object to XML that can be mapped to JavaScript Object Notation (JSON) using an XmlDictionaryWriter.

WriteStartObject(XmlWriter, Object)

使用 XmlWriter 寫入開頭 XML 項目,將物件序列化為可以對應至 JavaScript 物件標記法 (JSON) 的 XML。Writes the opening XML element for serializing an object to XML that can be mapped to JavaScript Object Notation (JSON) using an XmlWriter.

適用於