Share via


JsonArray Class

Definition

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.

public ref class JsonArray sealed : IIterable<IJsonValue ^>, IVector<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 JsonArray final : IIterable<IJsonValue>, IVector<IJsonValue>, 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 JsonArray final : IIterable<IJsonValue>, IVector<IJsonValue>, 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 JsonArray : IEnumerable<IJsonValue>, IList<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 JsonArray : IEnumerable<IJsonValue>, IList<IJsonValue>, IStringable
Public NotInheritable Class JsonArray
Implements IEnumerable(Of IJsonValue), IList(Of IJsonValue), IStringable
Inheritance
Object Platform::Object IInspectable JsonArray
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 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.

Constructors

JsonArray()

Creates a new JsonArray object that represents a JSON array.

Properties

Size

Gets the size (count) of the array.

ValueType

Gets the type of the values within the array. Possible types are defined by JsonValueType.

Methods

Append(IJsonValue)

Adds a new item to the array.

Clear()

Removes all items from the collection.

First()

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(UInt32)

Gets the JsonArray at the specified index if the ValueType of the encapsulated value is Array .

GetAt(UInt32)

Returns the item located at the specified index.

GetBoolean()

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

GetBooleanAt(UInt32)

Gets the Boolean value at the specified index if the ValueType of the value at that index is Boolean.

GetMany(UInt32, IJsonValue[])

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(UInt32)

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(UInt32)

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(UInt32)

Gets the String at the specified index if the ValueType of the encapsulated value is String.

GetView()

Gets a JsonArray view.

IndexOf(IJsonValue, UInt32)

Searches for a JsonValue object and returns the zero-based index of its first occurrence within the JsonArray.

InsertAt(UInt32, IJsonValue)

Inserts a JsonValue into an array at the specified index.

Parse(String)

Parses the specified JSON string that represents a JsonArray.

Note

This method 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 JsonArray.

RemoveAt(UInt32)

Removes the element at the specified index of the collection.

RemoveAtEnd()

Removes the last item in the array.

ReplaceAll(IJsonValue[])

Clears the array and then inserts the provided collection of JsonValue objects as new array items.

SetAt(UInt32, IJsonValue)

Sets the value at the specified index using the provided JsonValue.

Stringify()

Returns the JSON representation of the encapsulated value.

ToString()

Returns the JSON representation of the encapsulated value.

TryParse(String, JsonArray)

Parses the provided string into a JsonArray.

Applies to

See also