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 : Object, IJsonValue, IDictionary<String, IJsonValue>, IEnumerable<KeyValuePair>
Attributes
- ActivatableAttribute(NTDDI_WIN8)
- DualApiPartitionAttribute()
- MarshalingBehaviorAttribute(Agile)
- StaticAttribute(Windows.Data.Json.IJsonObjectStatics, NTDDI_WIN8)
- ThreadingAttribute(Both)
- VersionAttribute(NTDDI_WIN8)
- WebHostHiddenAttribute()
Members
The JsonObject class has these types of members:
Constructors
The JsonObject class has these constructors.
| Constructor | Description |
|---|---|
| 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.
| Method | Description |
|---|---|
| Add(KeyValuePair) [C#, VB] | Adds a new key-value pair to the JsonObject. |
| Add(String) [C#, VB] | Adds an item to the JsonObject. |
| Clear | Removes all items from the collection. |
| Contains [C#, VB] | Returns a value that indicates whether a specified key-value pair exists in the JsonObject. |
| ContainsKey [C#, VB] | Returns a value that indicates whether a specified key exists in the JsonObject. |
| CopyTo [C#, VB] | Copies the elements of the collection to an array, starting at a particular array index. |
| 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 | Gets the JsonArray value with the specified name, or NULL if no such named value is found. |
| GetNamedBoolean | Gets the Boolean value with the specified name, or NULL if no such named value is found. |
| GetNamedNumber | Gets the number value (a Double) with the specified name, or NULL if no such named value is found. |
| GetNamedObject | Gets the JsonObject value with the specified name, or NULL if no such named value is found. |
| GetNamedString | Gets the String value with the specified name, or NULL if no such named value is found. |
| GetNamedValue | Gets the specified JsonObject value. |
| 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 [C++] | Removes the JSON object associated with the specified key. |
| Remove(KeyValuePair) [C#, VB] | Removes a specific key-value pair from the JsonObject. |
| Remove(String) [C#, VB] | Removes a specific item from the JsonObject. |
| 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. |
| TryGetValue [C#, VB] | Returns a value that indicates whether a specified key exists in the JsonObject. If an item with that key exists, the item is retrieved as an out parameter. |
| TryParse | Parses the specified string that represents a JSON object into a JsonObject. |
Properties
The JsonObject class has these properties.
| Property | Access type | Description |
|---|---|---|
|
Count [C#, VB] | Read-only | Gets the number of elements contained in the collection. |
|
IsReadOnly [C#, VB] | Read-only | Gets a value indicating whether the dictionary is read-only. |
|
Item [C#, VB] | Read/write | Gets or sets the element value at the specified key index. |
|
Keys [C#, VB] | Read-only | Gets an ICollection object containing the keys of the JsonObject. |
|
Size [C++] | Read-only | Gets the size (count) of the collection. |
|
Values [C#, VB] | Read-only | Gets an ICollection object containing the values of the JsonObject . |
| Read-only | Gets 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
|
Minimum supported client | Windows 8 [Windows Store apps, desktop apps] |
|---|---|
|
Minimum supported server | Windows Server 2012 [Windows Store apps, desktop apps] |
|
Namespace |
|
|
Metadata |
|
See also
Build date: 12/4/2012
