JsonArray class

Applies to Windows and Windows Phone

Represents a JSON array.

JsonArray inherits the IVector(IJsonValue) and IIterable(IJsonValue) interfaces, which provide methods to iterate through the elements in the array and update its contents.

Syntax


public sealed class JsonArray : IJsonValue,
    IList<IJsonValue>,
    IEnumerable<IJsonValue>

Attributes

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

Members

The JsonArray class has these types of members:

Constructors

The JsonArray class has these constructors.

ConstructorDescription
JsonArray Creates a new JsonArray object that represents a JSON array.

 

Methods

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

MethodDescription
Add [C#, VB]Adds a new item to the collection.
Append [C++]Adds a new item to the array.
Clear Removes all items from the collection.
Contains [C#, VB]Determines whether an element is in the collection.
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 items in the array.
GetArray Gets the JsonArray if the ValueType of the encapsulated value is Array.
GetArrayAt Gets the JsonArray at the specified index if the ValueType of the encapsulated value is Array
GetAt [C++]Returns the item located at the specified index.
GetBoolean Gets the Boolean value if the ValueType of the encapsulated value is Boolean.
GetBooleanAt Gets the Boolean value at the specified index if the ValueType of the value at that index is Boolean.
GetMany [C++]Gets all array items of type IJsonValue, starting from a specified index.
GetNumber Gets the number (a Double) if the ValueType of the encapsulated value is Number.
GetNumberAt Gets the number (a Double) at the specified index if the ValueType of the value at that index is Number.
GetObject Gets the JsonObject if the ValueType of the encapsulated value is Object.
GetObjectAt Gets the JsonObject at the specified index if the ValueType of the encapsulated value is Object.
GetString Gets the String if the ValueType of the encapsulated value is String.
GetStringAt Gets the String at the specified index if the ValueType of the encapsulated value is String.
GetView [C++]Gets a JsonArray view.
IndexOf [C++]Searches for a JsonValue object and returns the zero-based index of its first occurrence within the JsonArray.
IndexOf [C#, VB]Determines the index of a specific item in the collection.
Insert [C#, VB]Inserts an item into the collection at the specified index.
InsertAt [C++]Inserts a JsonValue into an array at the specified index.
Parse Parses the specified JSON string that represents a JsonArray.
Remove [C#, VB]Removes the first occurrence of a specific object from the collection.
RemoveAt [C++]Removes the element at the specified index of the collection.
RemoveAt [C#, VB]Removes the element at the specified index of the collection.
RemoveAtEnd [C++]Removes the last item in the array.
ReplaceAll [C++]Clears the array and then inserts the provided collection of JsonValue objects as new array items.
SetAt [C++]Sets the value at the specified index using the provided JsonValue.
Stringify Returns the JSON representation of the encapsulated value.
TryParse Parses the provided string into a JsonArray.

 

Properties

The JsonArray 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 collection is read-only.

Item [C#, VB]

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

Size [C++]

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

ValueType

Read-onlyGets the type of the values within the array. Possible types are defined by JsonValueType.

 

Remarks

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

Enumerating the collection in C# or Microsoft Visual Basic

A JsonArray is enumerable, so you can use language-specific syntax such as foreach in C# to enumerate the items in the collection. The compiler does the type-casting for you and you won't need to cast to IEnumerable<IJsonValue> explicitly. If you do need to cast explicitly, for example if you want to call GetEnumerator, cast to IEnumerable<T> with an IJsonValue constraint.

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. All rights reserved.