JsonArray JsonArray JsonArray 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 : sealed class JsonArray : IJsonArray, IJsonValue, IIterable<IJsonValue>, IVector<IJsonValue>, IStringable
struct winrt::Windows::Data::Json::JsonArray : IJsonArray, IJsonValue, IIterable<IJsonValue>, IVector<IJsonValue>, IStringable
public sealed class JsonArray : IJsonArray, IJsonValue, IEnumerable<IJsonValue>, IList<IJsonValue>, IStringable
Public NotInheritable Class JsonArray Implements IJsonArray, IJsonValue, IEnumerable<IJsonValue>, IList<IJsonValue>, IStringable
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 with an IJsonValue constraint.

Constructors

JsonArray() JsonArray() JsonArray() JsonArray()

Creates a new JsonArray object that represents a JSON array.

Properties

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Gets or sets the element at the specified index.

Size Size Size Size

Gets the size (count) of the array.

ValueType ValueType ValueType ValueType

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

Methods

Append(IJsonValue) Append(IJsonValue) Append(IJsonValue) Append(IJsonValue)

Adds a new item to the array.

Clear() Clear() Clear() Clear()

Removes all items from the collection.

First() First() First() First()

Returns the iterator for iteration over the items in the array.

GetArray() GetArray() GetArray() GetArray()

Gets the JsonArray if the ValueType of the encapsulated value is Array.

GetArrayAt(UInt32) GetArrayAt(UInt32) GetArrayAt(UInt32) GetArrayAt(UInt32)

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

GetAt(UInt32) GetAt(UInt32) GetAt(UInt32) GetAt(UInt32)

Returns the item located at the specified index.

GetBoolean() GetBoolean() GetBoolean() GetBoolean()

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

GetBooleanAt(UInt32) GetBooleanAt(UInt32) GetBooleanAt(UInt32) GetBooleanAt(UInt32)

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

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator that iterates through the collection.

GetMany(UInt32, IJsonValue[]) GetMany(UInt32, IJsonValue[]) GetMany(UInt32, IJsonValue[]) GetMany(UInt32, IJsonValue[])

Gets all array items of type IJsonValue, starting from a specified index.

GetNumber() GetNumber() GetNumber() GetNumber()

Gets the number (a Double) if the ValueType of the encapsulated value is Number.

GetNumberAt(UInt32) GetNumberAt(UInt32) GetNumberAt(UInt32) GetNumberAt(UInt32)

Gets the number (a Double) at the specified index if the ValueType of the value at that index is Number.

GetObject() GetObject() GetObject() GetObject()

Gets the JsonObject if the ValueType of the encapsulated value is Object.

GetObjectAt(UInt32) GetObjectAt(UInt32) GetObjectAt(UInt32) GetObjectAt(UInt32)

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

GetString() GetString() GetString() GetString()

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

GetStringAt(UInt32) GetStringAt(UInt32) GetStringAt(UInt32) GetStringAt(UInt32)

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

GetView() GetView() GetView() GetView()

Gets a JsonArray view.

IndexOf(T) IndexOf(T) IndexOf(T) IndexOf(T)

Determines the index of a specific item in the System.Collections.Generic.IList`1.

IndexOf(IJsonValue, UInt32) IndexOf(IJsonValue, UInt32) IndexOf(IJsonValue, UInt32) IndexOf(IJsonValue, UInt32)

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

Insert(Int32, T) Insert(Int32, T) Insert(Int32, T) Insert(Int32, T)

Inserts an item to the System.Collections.Generic.IList`1 at the specified index.

InsertAt(UInt32, IJsonValue) InsertAt(UInt32, IJsonValue) InsertAt(UInt32, IJsonValue) InsertAt(UInt32, IJsonValue)

Inserts a JsonValue into an array at the specified index.

Parse(String) Parse(String) Parse(String) 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(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

Removes the System.Collections.Generic.IList`1 item at the specified index.

RemoveAt(UInt32) RemoveAt(UInt32) RemoveAt(UInt32) RemoveAt(UInt32)

Removes the element at the specified index of the collection.

RemoveAtEnd() RemoveAtEnd() RemoveAtEnd() RemoveAtEnd()

Removes the last item in the array.

ReplaceAll(IJsonValue[]) ReplaceAll(IJsonValue[]) ReplaceAll(IJsonValue[]) ReplaceAll(IJsonValue[])

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

SetAt(UInt32, IJsonValue) SetAt(UInt32, IJsonValue) SetAt(UInt32, IJsonValue) SetAt(UInt32, IJsonValue)

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

Stringify() Stringify() Stringify() Stringify()

Returns the JSON representation of the encapsulated value.

ToString() ToString() ToString() ToString()

Returns the JSON representation of the encapsulated value.

TryParse(String, JsonArray) TryParse(String, JsonArray) TryParse(String, JsonArray) TryParse(String, JsonArray)

Parses the provided string into a JsonArray.

See Also