次の方法で共有


JsonObject.TryGetValue Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Attempts to get the value that corresponds to the specified key.

Namespace:  System.Json
Assembly:  System.Json (in System.Json.dll)

Syntax

'Declaration
Public Function TryGetValue ( _
    key As String, _
    <OutAttribute> ByRef value As JsonValue _
) As Boolean
public bool TryGetValue(
    string key,
    out JsonValue value
)

Parameters

Return Value

Type: System.Boolean
true if the instance of the JsonObject contains an element with the specified key; otherwise, false.

Implements

IDictionary<TKey, TValue>.TryGetValue(TKey, TValue%)

Exceptions

Exception Condition
ArgumentNullException

key is nulla null reference (Nothing in Visual Basic).

Remarks

This method combines the functionality of the ContainsKey method and the Item() property. If the key is not found, then the value is set to nulla null reference (Nothing in Visual Basic).

Use the TryGetValue() method if your code frequently attempts to access keys that are not in the JsonValue object. Using this method is more efficient than catching the KeyNotFoundException thrown by the Item() method.

Version Information

Silverlight

Supported in: 5, 4, 3

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.