JsonObject class

Applies to Windows and Windows Phone

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>

Attributes

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

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]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
GetNamedArray(String) Gets the JsonArray value with the specified name.
GetNamedBoolean
GetNamedBoolean(String) Gets the Boolean value with the specified name.
GetNamedNumber
GetNamedNumber(String) Gets the number value (a Double) with the specified name.
GetNamedObject
GetNamedObject(String) Gets the JsonObject value with the specified name.
GetNamedString
GetNamedString(String) Gets the String value with the specified name.
GetNamedValue
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 [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.

PropertyAccess typeDescription

Count [C#, VB]

Read-onlyGets the number of elements contained in the collection.

IsReadOnly [C#, VB]

Read-onlyGets a value indicating whether the dictionary is read-only.

Item [C#, VB]

Read/writeGets or sets the element value at the specified key index.

Keys [C#, VB]

Read-onlyGets an ICollection object containing the keys of the JsonObject.

Size [C++]

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

Values [C#, VB]

Read-onlyGets an ICollection object containing the values of the JsonObject .

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

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

See also

Using JavaScript Object Notation (JSON)

 

 

Show:
© 2014 Microsoft