JsonObject.TryGetValue Method

Silverlight

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

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

public bool TryGetValue(
	string key,
	out JsonValue value
)

Parameters

key
Type: System.String
The key of the value to retrieve.
value
Type: System.Json.JsonValue%
The primitive or structured JsonValue object that has the key specified. This parameter is passed uninitialized.

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)

ExceptionCondition
ArgumentNullException

key is null.

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 null.

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.

Silverlight

Supported in: 5, 4, 3

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

Community Additions

ADD
Show: