Share via


JsonElement.TryGetProperty 方法

定義

多載

TryGetProperty(String, JsonElement)

尋找目前物件中名為 propertyName 的屬性,並傳回指出這類屬性是否存在的值。 當屬性存在時,會將其值指派給 value 引數。

TryGetProperty(ReadOnlySpan<Byte>, JsonElement)

尋找目前物件中名為 utf8PropertyName 的屬性,並傳回指出這類屬性是否存在的值。 當屬性存在時,方法會將其值指派給 value 引數。

TryGetProperty(ReadOnlySpan<Char>, JsonElement)

尋找目前物件中名為 propertyName 的屬性,並傳回指出這類屬性是否存在的值。 當屬性存在時,方法會將其值指派給 value 引數。

TryGetProperty(String, JsonElement)

尋找目前物件中名為 propertyName 的屬性,並傳回指出這類屬性是否存在的值。 當屬性存在時,會將其值指派給 value 引數。

public:
 bool TryGetProperty(System::String ^ propertyName, [Runtime::InteropServices::Out] System::Text::Json::JsonElement % value);
public bool TryGetProperty (string propertyName, out System.Text.Json.JsonElement value);
member this.TryGetProperty : string * JsonElement -> bool
Public Function TryGetProperty (propertyName As String, ByRef value As JsonElement) As Boolean

參數

propertyName
String

要尋找的屬性名稱。

value
JsonElement

當這個方法傳回時,會包含指定屬性的值。

傳回

Boolean

若找到屬性,則為 true;否則為 false

例外狀況

propertyNamenull

JsonDocument 已經過處置。

備註

屬性名稱比對會以序數、區分大小寫的比較方式執行。

如果相同物件多次定義屬性,則方法會比對最後一個這類定義。

適用於

TryGetProperty(ReadOnlySpan<Byte>, JsonElement)

尋找目前物件中名為 utf8PropertyName 的屬性,並傳回指出這類屬性是否存在的值。 當屬性存在時,方法會將其值指派給 value 引數。

public:
 bool TryGetProperty(ReadOnlySpan<System::Byte> utf8PropertyName, [Runtime::InteropServices::Out] System::Text::Json::JsonElement % value);
public bool TryGetProperty (ReadOnlySpan<byte> utf8PropertyName, out System.Text.Json.JsonElement value);
member this.TryGetProperty : ReadOnlySpan<byte> * JsonElement -> bool
Public Function TryGetProperty (utf8PropertyName As ReadOnlySpan(Of Byte), ByRef value As JsonElement) As Boolean

參數

utf8PropertyName
ReadOnlySpan<Byte>

要傳回的屬性名稱 UTF-8 表示 (沒有位元組順序標記 (BOM))。

value
JsonElement

接收所找到的屬性值。

傳回

Boolean

若找到屬性,則為 true;否則為 false

例外狀況

JsonDocument 已經過處置。

備註

屬性名稱比對會以序數、區分大小寫的比較方式執行。

如果相同物件多次定義屬性,則方法會比對最後一個這類定義。

如需詳細資訊,請參閱 如何使用 System.Text.Json 撰寫自訂序列化程式和還原序列化程式

適用於

TryGetProperty(ReadOnlySpan<Char>, JsonElement)

尋找目前物件中名為 propertyName 的屬性,並傳回指出這類屬性是否存在的值。 當屬性存在時,方法會將其值指派給 value 引數。

public:
 bool TryGetProperty(ReadOnlySpan<char> propertyName, [Runtime::InteropServices::Out] System::Text::Json::JsonElement % value);
public bool TryGetProperty (ReadOnlySpan<char> propertyName, out System.Text.Json.JsonElement value);
member this.TryGetProperty : ReadOnlySpan<char> * JsonElement -> bool
Public Function TryGetProperty (propertyName As ReadOnlySpan(Of Char), ByRef value As JsonElement) As Boolean

參數

propertyName
ReadOnlySpan<Char>

要尋找的屬性名稱。

value
JsonElement

當這個方法傳回時,會包含指定屬性的值。

傳回

Boolean

若找到屬性,則為 true;否則為 false

例外狀況

JsonDocument 已經過處置。

備註

屬性名稱比對會以序數、區分大小寫的比較方式執行。

如果相同物件多次定義屬性,則方法會比對最後一個這類定義。

適用於