JsonObject class

JsonObject class

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.

Syntax


public sealed class JsonObject : IJsonValue,
    IDictionary<String, IJsonValue>,
    IEnumerable<KeyValuePair>

Members

The JsonObject class has these types of members:

Constructors

The JsonObject class has these constructors.

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

 

Methods

The JsonObject class has these methods. It also inherits methods from the Object class.

MethodDescription
Add(KeyValuePair) [C#, VB]
Add(String) [C#, VB]
Clear Removes all items from the collection.
Contains [C#, VB]
ContainsKey [C#, VB]
CopyTo [C#, VB]
First [C++]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) Gets the JsonArray value with the specified name.
GetNamedArray(String, JsonArray) Gets the JsonArray 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.
GetNamedBoolean(String, Boolean) Gets the Boolean value 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.
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.
GetNamedObject(String) Gets the JsonObject value 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.
GetNamedString(String) Gets the String 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.
GetNamedValue(String) Gets the JsonValue 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.
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 [C++]Gets a JsonObject view.
HasKey [C++]Indicates whether the JsonObject has an entry with the requested key.
Insert [C++]Adds a new entry to the JsonObject.
Lookup [C++]Gets the JSON value associated with the supplied key, if an entry with that key exists.
Parse Parses the specified JSON string that represents a JsonObject into a JSON value.
Remove(KeyValuePair) [C#, VB]
Remove(String) [C#, VB]
SetNamedValue 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.
TryGetValue [C#, VB]
TryParse Parses the specified string that represents a JSON object into a JsonObject.

 

Properties

The JsonObject class has these properties.

PropertyAccess typeDescription

Count [C#, VB]

Read-only

IsReadOnly [C#, VB]

Read-only

Item [C#, VB]

Read/write

Keys [C#, VB]

Read-only

Size [C++]

Read-onlyGets the size (count) of the collection.

Values [C#, VB]

Read-only

ValueType

Read-onlyGets the type of the encapsulated JSON value. Possible types are defined by JsonValueType.

 

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

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Data.Json
Windows::Data::Json [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps, desktop apps]

Minimum supported server

Windows Server 2012 [Windows Store apps, desktop apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

Windows.Data.Json
Windows::Data::Json [C++]

Metadata

Windows.winmd

Attributes

[DualApiPartition()]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]
[WebHostHidden()]

See also

Object
IJsonValue
IMap(String, IJsonValue)
IIterable(IKeyValuePair)
Using JavaScript Object Notation (JSON)

 

 

Show:
© 2016 Microsoft