JsonElement.TryGetProperty 方法
定义
重载
| TryGetProperty(String, JsonElement) |
查找当前对象中名为 |
| TryGetProperty(ReadOnlySpan<Byte>, JsonElement) |
查找当前对象中名为 |
| TryGetProperty(ReadOnlySpan<Char>, JsonElement) |
查找当前对象中名为 |
TryGetProperty(String, JsonElement)
查找当前对象中名为 propertyName 的属性,返回一个指示此类属性是否存在的值。Looks for a property named propertyName in the current object, returning a value that indicates whether or not such a property exists. 如果此属性存在,会将其值分配给 value 参数。When the property exists, its value is assigned to the value argument.
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
要查找的属性的名称。The name of the property to find.
- value
- JsonElement
此方法返回时,包含指定属性的值。When this method returns, contains the value of the specified property.
返回
如果找到该属性,则为 true;否则为 false。true if the property was found; otherwise, false.
例外
propertyName 为 null。propertyName is null.
已释放父级 JsonDocument。The parent JsonDocument has been disposed.
注解
属性名称匹配作为序号、区分大小写的比较来执行。Property name matching is performed as an ordinal, case-sensitive comparison.
如果为同一对象多次定义某个属性,则该方法将匹配最后一个此类定义。If a property is defined multiple times for the same object, the method matches the last such definition.
适用于
TryGetProperty(ReadOnlySpan<Byte>, JsonElement)
查找当前对象中名为 utf8PropertyName 的属性,返回一个指示此类属性是否存在的值。Looks for a property named utf8PropertyName in the current object, returning a value that indicates whether or not such a property exists. 如果此属性存在,该方法会将其值分配给 value 参数。When the property exists, the method assigns its value to the value argument.
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))。The UTF-8 (with no Byte-Order-Mark (BOM)) representation of the name of the property to return.
- value
- JsonElement
接收已找到的属性的值。Receives the value of the located property.
返回
如果找到该属性,则为 true;否则为 false。true if the property was found; otherwise, false.
例外
已释放父级 JsonDocument。The parent JsonDocument has been disposed.
注解
属性名称匹配作为序号、区分大小写的比较来执行。Property name matching is performed as an ordinal, case-sensitive comparison.
如果为同一对象多次定义某个属性,则该方法将匹配最后一个此类定义。If a property is defined multiple times for the same object, the method matches the last such definition.
有关详细信息,请参阅 如何在上编写自定义序列化程序和反 System.Text.Js。For more information, see How to write custom serializers and deserializers with System.Text.Json.
适用于
TryGetProperty(ReadOnlySpan<Char>, JsonElement)
查找当前对象中名为 propertyName 的属性,返回一个指示此类属性是否存在的值。Looks for a property named propertyName in the current object, returning a value that indicates whether or not such a property exists. 如果此属性存在,该方法会将其值分配给 value 参数。When the property exists, the method assigns its value to the value argument.
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>
要查找的属性的名称。The name of the property to find.
- value
- JsonElement
此方法返回时,包含指定属性的值。When this method returns, contains the value of the specified property.
返回
如果找到该属性,则为 true;否则为 false。true if the property was found; otherwise, false.
例外
已释放父级 JsonDocument。The parent JsonDocument has been disposed.
注解
属性名称匹配作为序号、区分大小写的比较来执行。Property name matching is performed as an ordinal, case-sensitive comparison.
如果为同一对象多次定义某个属性,则该方法将匹配最后一个此类定义。If a property is defined multiple times for the same object, the method matches the last such definition.