JsonSerializerOptions 類別

定義

提供與 JsonSerializer搭配使用的選項。

public ref class JsonSerializerOptions sealed
public sealed class JsonSerializerOptions
type JsonSerializerOptions = class
Public NotInheritable Class JsonSerializerOptions
繼承
JsonSerializerOptions

備註

如需詳細資訊,請參閱 如何串行化和還原串行化 JSON

建構函式

JsonSerializerOptions()

初始化 JsonSerializerOptions 類別的新實例。

JsonSerializerOptions(JsonSerializerDefaults)

使用指定的 JsonSerializerDefaults所決定的預先定義選項集,建構新的 JsonSerializerOptions 實例。

JsonSerializerOptions(JsonSerializerOptions)

將選項從 JsonSerializerOptions 實例複製到新的實例。

屬性

AllowOutOfOrderMetadataProperties

允許在還原串行化 JSON 物件中的一般屬性之後指定 JSON 元數據屬性。

AllowTrailingCommas

取得或設定值,這個值表示在物件或陣列中 JSON 值清單結尾是否允許額外的逗號,並在要還原串行化的 JSON 承載內被忽略。

Converters

取得已註冊的使用者定義轉換器清單。

Default

取得使用預設組態之 JsonSerializerOptions 的唯讀單一實例。

DefaultBufferSize

取得或設定建立暫存緩衝區時要使用的默認緩衝區大小,以位元組為單位。

DefaultIgnoreCondition

取得或設定值,這個值會決定串行化或還原串行化期間何時忽略具有預設值的屬性。 預設值為 Never

DictionaryKeyPolicy

取得或設定用來將 IDictionary 索引鍵名稱轉換成另一種格式的原則,例如駱駝大小寫。

Encoder

取得或設定逸出字串時要使用的編碼器,或 null 使用預設編碼器。

IgnoreNullValues
已淘汰.

取得或設定值,這個值表示串行化和還原串行化期間是否忽略 null 值。 預設值為 false

IgnoreReadOnlyFields

取得或設定值,這個值表示串行化期間是否忽略唯讀欄位。 如果欄位以 readonly 關鍵詞標示,則欄位是唯讀的。 預設值為 false

IgnoreReadOnlyProperties

取得值,這個值表示串行化期間是否忽略唯讀屬性。 預設值為 false

IncludeFields

取得或設定值,這個值表示是否在串行化和還原串行化期間處理字段。 預設值為 false

IndentCharacter

定義啟用 WriteIndented 時所使用的縮排字元。 預設為空格字元。

IndentSize

定義啟用 WriteIndented 時所使用的縮排大小。 預設值為 2。

IsReadOnly

取得值,這個值表示目前實例是否已鎖定以供使用者修改。

MaxDepth

取得或設定串行化或還原串行化 JSON 時允許的最大深度,預設值為 0,表示最大深度為 64。

NewLine

取得或設定 WriteIndentedtrue時要使用的新行字串。

預設值為 NewLine的值。

NumberHandling

取得或設定 物件,指定串行化或還原串行化時應該如何處理數位型別。

PreferredObjectCreationHandling

取得或設定還原串行化 JSON 時屬性的慣用物件建立處理。

PropertyNameCaseInsensitive

取得或設定值,這個值表示屬性的名稱在還原串行化期間是否使用不區分大小寫的比較。 預設值為 false

PropertyNamingPolicy

取得或設定值,指定用來將物件上的屬性名稱轉換成另一種格式的原則,例如 camel-casing,或 null 讓屬性名稱保持不變。

ReadCommentHandling

取得或設定值,這個值定義還原串行化期間如何處理批注。

ReferenceHandler

取得或設定 物件,指定讀取和寫入 JSON 時,對象參考的處理方式。

RespectNullableAnnotations

取得或設定值,這個值表示串行化和還原串行化期間是否應該遵守可為 Null 的批注。

RespectRequiredConstructorParameters

取得或設定值,這個值表示是否應在還原串行化期間指定非選擇性建構函式參數。

TypeInfoResolver

取得或設定這個實例所使用的 JsonTypeInfo 合約解析程式。

TypeInfoResolverChain

取得這個實例所使用的鏈結 JsonTypeInfo 合約解析程式清單。

UnknownTypeHandling

取得或設定 對象,這個物件會指定還原串行化宣告為 Object 的類型在還原串行化期間如何處理。

UnmappedMemberHandling

取得或設定 物件,指定 JsonSerializer 如何處理還原串行化物件類型時無法對應至特定 .NET 成員的 JSON 屬性。

Web

取得使用 Web 組態之 JsonSerializerOptions 的唯讀單一實例。

WriteIndented

取得或設定值,指出 JSON 是否應該使用漂亮的列印。 根據預設,JSON 會串行化,沒有任何額外的空格符。

方法

AddContext<TContext>()
已淘汰.

將新的 JsonSerializerContext 附加至目前 JsonSerializerOptions 實例的元數據解析。

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetConverter(Type)

傳回指定型別的轉換器。

GetHashCode()

做為預設哈希函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

(繼承來源 Object)
GetTypeInfo(Type)

取得目前 JsonSerializerOptions 實例解析的 JsonTypeInfo 合約元數據。

MakeReadOnly()

將目前的實例標示為唯讀,以防止任何進一步的使用者修改。

MakeReadOnly(Boolean)

將目前的實例標示為唯讀,以防止任何進一步的使用者修改。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

(繼承來源 Object)
TryGetTypeInfo(Type, JsonTypeInfo)

嘗試取得目前 JsonSerializerOptions 實例解析的 JsonTypeInfo 合約元數據。

擴充方法

GetJsonSchemaAsNode(JsonSerializerOptions, Type, JsonSchemaExporterOptions)

取得 type 作為 JsonNode 檔的 JSON 架構。

適用於