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, IVector, IStringablepublic sealed class JsonArray : IJsonArray, IJsonValue, IEnumerable, IList, IStringablePublic NotInheritable Class JsonArray Implements IJsonArray, IJsonValue, IEnumerable, IList, IStringable// This API is not available in Javascript.
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.

public : JsonArray()public JsonArray()Public Sub New()// This API is not available in Javascript.

Properties

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

Gets or sets the element at the specified index.

This member is not implemented in C++T this[int index] { get; set; }Property Item(index As Integer) As TT this[int index] { get; set; }
Parameters
index

The zero-based index of the element to get or set.

Value
T T T T

The element at the specified index.

Exceptions

index is not a valid index in the System.Collections.Generic.IList`1.

The property is set and the System.Collections.Generic.IList`1 is read-only.

Size Size Size Size

Gets the size (count) of the array.

public : unsigned int Size { get; }This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Value
unsigned int uint uint uint

The count of items in the array.

ValueType ValueType ValueType ValueType

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

public : JsonValueType ValueType { get; }public JsonValueType ValueType { get; }Public ReadOnly Property ValueType As JsonValueType// This API is not available in Javascript.

Methods

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

Adds a new item to the array.

public : void Append(IJsonValue value)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Parameters
value
IJsonValue IJsonValue IJsonValue IJsonValue

The new item to add.

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

Removes all items from the collection.

public : void Clear()This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.

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

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

public : IIterator<IJsonValue> First()This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Returns

The iterator object. The iterator's current position is at the 0-index position, or at the array end if the array is empty.

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

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

public : JsonArray GetArray()public JsonArray GetArray()Public Function GetArray() As JsonArray// This API is not available in Javascript.
Returns

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

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

public : JsonArray GetArrayAt(unsigned int index)public JsonArray GetArrayAt(UInt32 index)Public Function GetArrayAt(index As UInt32) As JsonArray// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The specified index.

Returns

The JsonArray at the specified index.

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

Returns the item located at the specified index.

public : IJsonValue GetAt(unsigned int index)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The integer index for the value to retrieve.

Returns

The JsonValue at the specified index.

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

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

public : PlatForm::Boolean GetBoolean()public bool GetBoolean()Public Function GetBoolean() As bool// This API is not available in Javascript.
Returns
PlatForm::Boolean bool bool bool

The Boolean value.

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.

public : PlatForm::Boolean GetBooleanAt(unsigned int index)public bool GetBooleanAt(UInt32 index)Public Function GetBooleanAt(index As UInt32) As bool// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The specified index.

Returns
PlatForm::Boolean bool bool bool

The Boolean value at the specified index.

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

Returns an enumerator that iterates through the collection.

This member is not implemented in C++IEnumerator<T> GetEnumerator()Function GetEnumerator As IEnumerator(Of T)IEnumerator<T> GetEnumerator()
Returns

An enumerator that can be used to iterate 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.

public : unsigned int GetMany(unsigned int startIndex, IJsonValue[] items)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Parameters
startIndex
unsigned int UInt32 UInt32 UInt32

The starting index.

items
IJsonValue[] IJsonValue[] IJsonValue[] IJsonValue[]

Returns items of the IJsonValue.

Returns
unsigned int uint uint uint

The index of items within the range of elements in an array that starts at startIndex.

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

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

public : double GetNumber()public double GetNumber()Public Function GetNumber() As double// This API is not available in Javascript.
Returns
double double double double

The number value.

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.

public : double GetNumberAt(unsigned int index)public double GetNumberAt(UInt32 index)Public Function GetNumberAt(index As UInt32) As double// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The specified index.

Returns
double double double double

The number value at the specified index.

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

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

public : JsonObject GetObject()public JsonObject GetObject()Public Function GetObject() As JsonObject// This API is not available in Javascript.
Returns

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

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

public : JsonObject GetObjectAt(unsigned int index)public JsonObject GetObjectAt(UInt32 index)Public Function GetObjectAt(index As UInt32) As JsonObject// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The specified index.

Returns

The JsonObject at the specified index.

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

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

public : PlatForm::String GetString()public string GetString()Public Function GetString() As string// This API is not available in Javascript.
Returns
PlatForm::String string string string

The String value.

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

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

public : PlatForm::String GetStringAt(unsigned int index)public string GetStringAt(UInt32 index)Public Function GetStringAt(index As UInt32) As string// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The specified index.

Returns
PlatForm::String string string string

The String value at the specified index.

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

Gets a JsonArray view.

public : IVectorView<IJsonValue> GetView()This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Returns
IVectorView<IJsonValue> IReadOnlyList<IJsonValue> IReadOnlyList<IJsonValue> IReadOnlyList<IJsonValue>

The JsonArray view.

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

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

This member is not implemented in C++int IndexOf(T item)Function IndexOf(item As T) As Integerint IndexOf(T item)
Parameters
item
T T T T

The object to locate in the System.Collections.Generic.IList`1.

Returns

The index of item if found in the list; otherwise, -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.

public : PlatForm::Boolean IndexOf(IJsonValue value, unsigned int index)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The zero-based index of the first occurrence of item within the JsonArray, if found; otherwise, –1.

Returns
PlatForm::Boolean bool bool bool

Returns a Boolean value indicating if an occurrence of value was found.

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.

This member is not implemented in C++void Insert(int index, T item)Sub Insert(index As Integer, item As T)void Insert(int index, T item)
Parameters
index

The zero-based index at which item should be inserted.

item
T T T T

The object to insert into the System.Collections.Generic.IList`1.

Exceptions

index is not a valid index in the System.Collections.Generic.IList`1.

The System.Collections.Generic.IList`1 is read-only.

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

Inserts a JsonValue into an array at the specified index.

public : void InsertAt(unsigned int index, IJsonValue value)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The zero-based index at which the item should be inserted.

value
IJsonValue IJsonValue IJsonValue IJsonValue

The IJsonValue object to insert.

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.

public : static JsonArray Parse(PlatForm::String input)public static JsonArray Parse(String input)Public Static Function Parse(input As String) As JsonArray// This API is not available in Javascript.
Parameters
input
PlatForm::String String String String

The specified JSON string.

Returns

Remarks

This method may only be called when the ValueType is Null. If the value contained in the specified JSON string is a String, a Number or a Boolean, the ValueType will be updated and the actual value can then be accessed through the GetString, GetNumber or GetBoolean methods. If Parse fails due to an invalid JSON string or resource allocation errors, the ValueType will not be changed.

When implemented on the subclass JsonObject, this method requires the specified input string to be a valid JSON object value. When implemented on the subclass JsonArray, this method requires the specified input string to be a valid JSON array value. The original object state will be overwritten when JsonObject.@Windows.Data.Json.JsonValue.Parse(System.String)?text=Parse or JsonArray.@Windows.Data.Json.JsonValue.Parse(System.String)?text=Parse succeeds. If Parse fails, the object state remains intact.

RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32) RemoveAt(Int32)

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

This member is not implemented in C++void RemoveAt(int index)Sub RemoveAt(index As Integer)void RemoveAt(int index)
Parameters
index

The zero-based index of the item to remove.

Exceptions

index is not a valid index in the System.Collections.Generic.IList`1.

The System.Collections.Generic.IList`1 is read-only.

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

Removes the element at the specified index of the collection.

public : void RemoveAt(unsigned int index)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The zero-based index of the element to remove.

Remarks

If successful, calling this method reduces the collection size by one. Items with index values greater than the called index have their index values reduced by one.

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

Removes the last item in the array.

public : void RemoveAtEnd()This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.

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

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

public : void ReplaceAll(IJsonValue[] items)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Parameters
items
IJsonValue[] IJsonValue[] IJsonValue[] IJsonValue[]

The new collection items.

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

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

public : void SetAt(unsigned int index, IJsonValue value)This member is not implemented in C#This member is not implemented in VB.Net// This API is not available in Javascript.
Parameters
index
unsigned int UInt32 UInt32 UInt32

The index at which to set the value.

value
IJsonValue IJsonValue IJsonValue IJsonValue

The value to set.

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

Returns the JSON representation of the encapsulated value.

public : PlatForm::String Stringify()public string Stringify()Public Function Stringify() As string// This API is not available in Javascript.
Returns
PlatForm::String string string string

A JSON representation of the encapsulated value.

Remarks

If the ValueType is String, then the returned string will be properly escaped and double quoted. This method is used for serializing the encapsulated value into a valid JSON format.

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

Returns the JSON representation of the encapsulated value.

public : PlatForm::String ToString()public string ToString()Public Function ToString() As string// This API is not available in Javascript.
Returns
PlatForm::String string string string

A JSON representation of the encapsulated value.

Remarks

If the ValueType is String, then the returned string will be properly escaped and double quoted. This method is used for serializing the encapsulated value into a valid JSON format.

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

Parses the provided string into a JsonArray.

public : static PlatForm::Boolean TryParse(PlatForm::String input, JsonArray result)public static bool TryParse(String input, JsonArray result)Public Static Function TryParse(input As String, result As JsonArray) As bool// This API is not available in Javascript.
Parameters
input
PlatForm::String String String String

The specified string.

Returns
PlatForm::Boolean bool bool bool

True if the JsonValue object was successfully created; otherwise, false.

See Also