Delen via


JsonObject Class

Definition

Represents a JSON object containing a collection of name and JsonValue pairs.

JsonObject is an activatable class that implements JsonValue and the IMap<String,IJsonValue> interface such that its name/value pairs can be manipulated like a dictionary. When there are values with duplicated names, the last name/value pair will be stored.

public ref class JsonObject sealed : IIterable<IKeyValuePair<Platform::String ^, IJsonValue ^> ^>, IMap<Platform::String ^, IJsonValue ^>, IStringable
/// [Windows.Foundation.Metadata.Activatable(65536, Windows.Foundation.UniversalApiContract)]
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class JsonObject final : IIterable<IKeyValuePair<winrt::hstring, IJsonValue const&>>, IMap<winrt::hstring, IJsonValue const&>, IStringable
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
/// [Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
class JsonObject final : IIterable<IKeyValuePair<winrt::hstring, IJsonValue const&>>, IMap<winrt::hstring, IJsonValue const&>, IStringable
[Windows.Foundation.Metadata.Activatable(65536, typeof(Windows.Foundation.UniversalApiContract))]
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class JsonObject : IDictionary<string,IJsonValue>, IEnumerable<KeyValuePair<string,IJsonValue>>, IStringable
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
[Windows.Foundation.Metadata.Activatable(65536, "Windows.Foundation.UniversalApiContract")]
public sealed class JsonObject : IDictionary<string,IJsonValue>, IEnumerable<KeyValuePair<string,IJsonValue>>, IStringable
Public NotInheritable Class JsonObject
Implements IDictionary(Of String, IJsonValue), IEnumerable(Of KeyValuePair(Of String, IJsonValue)), IStringable
Inheritance
Object Platform::Object IInspectable JsonObject
Attributes
Implements

Windows requirements

Device family
Windows 10 (introduced in 10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v1.0)

Remarks

For an example of how these class methods are used to parse an object from a JSON string and convert it into a JsonObject object, update the name/value pairs the object contains, and then serialize the updated JsonObject object as a JSON string, see Using JavaScript Object Notation (JSON).

Constructors

JsonObject()

Initializes a new instance of a JsonObject that represents a JSON object containing a collection of name and JsonValue pairs.

Properties

Size

Gets the size (count) of the collection.

ValueType

Gets the type of the encapsulated JSON value. Possible types are defined by JsonValueType.

Methods

Clear()

Removes all items from the collection.

First()

Returns the iterator for iteration over the key/value pairs in the JsonObject.

GetArray()

Returns a JsonArray if the ValueType of the encapsulated value is Array.

GetBoolean()

Gets a Boolean if the ValueType of the encapsulated value is Boolean.

GetNamedArray(String, JsonArray)

Gets the JsonArray value with the specified name, or the provided default value if no such named value is found.

GetNamedArray(String)

Gets the JsonArray value with the specified name.

GetNamedBoolean(String, Boolean)

Gets the Boolean value with the specified name, or the provided default value if no such named value is found.

GetNamedBoolean(String)

Gets the Boolean value with the specified name.

GetNamedNumber(String, Double)

Gets the number value (a Double) with the specified name, or the provided default value if no such named value is found.

GetNamedNumber(String)

Gets the number value (a Double) with the specified name.

GetNamedObject(String, JsonObject)

Gets the JsonObject value with the specified name, or the provided default value if no such named value is found.

GetNamedObject(String)

Gets the JsonObject value with the specified name.

GetNamedString(String, String)

Gets the String value with the specified name, or the provided default value if no such named value is found.

GetNamedString(String)

Gets the String value with the specified name.

GetNamedValue(String, JsonValue)

Gets the specified JsonValue value, or the provided default value if no such named value is found.

GetNamedValue(String)

Gets the JsonValue value with the specified name.

GetNumber()

Gets the number (a Double) if the ValueType of the encapsulated value is Number.

GetObject()

Gets the JsonObject if the ValueType of the encapsulated value is Object.

GetString()

Gets the String if the ValueType of the encapsulated value is String.

GetView()

Gets a JsonObject view.

HasKey(String)

Indicates whether the JsonObject has an entry with the requested key.

Insert(String, IJsonValue)

Adds a new entry to the JsonObject.

Lookup(String)

Gets the JSON value associated with the supplied key, if an entry with that key exists.

Parse(String)

Parses the specified JSON string that represents a JsonObject into a JSON value.

Note

This will throw an exception if the provided JSON string is not valid. Use of JsonObject.TryParse is a recommended alternative. A TryParse call will return a boolean value to indicate success or failure and, if successful, the resultant JsonObject.

Remove(String)

Removes a specific item from the JsonObject.

SetNamedValue(String, IJsonValue)

Sets the value of the first JsonValue object with the specified name to the specified value. If no such object is found, a new name and JsonValue pair is inserted into the JSON object.

Stringify()

Retrieves the JSON representation of the encapsulated value.

ToString()

Retrieves the JSON representation of the encapsulated value.

TryParse(String, JsonObject)

Parses the specified string that represents a JSON object into a JsonObject.

Applies to

See also