JsonArray JsonArray JsonArray Class

Definition

Represents a JSON array.

@Windows.Data.Json.JsonArray.#ctor?text=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
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<T> with an IJsonValue constraint.

Constructors

JsonArray() JsonArray() JsonArray()

Creates a new JsonArray object that represents a JSON array.

public JsonArray()public JsonArray()Public Sub New()
Attributes

Properties

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 T
Parameters
index
System.Int32 System.Int32 System.Int32

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

Value
T T T

The element at the specified index.

Attributes
See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

Size Size Size

Gets the size (count) of the array.

public uint Size { get; }This member is not implemented in C#This member is not implemented in VB.Net
Value
uint uint uint

The count of items in the array.

Attributes

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
Value
JsonValueType JsonValueType JsonValueType

The JSON value type.

Attributes

Methods

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
Parameters
value
IJsonValue IJsonValue IJsonValue

The new item to add.

Attributes

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
Attributes

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
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.

Attributes

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
Returns
Attributes

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(UInt32 index)public JsonArray GetArrayAt(UInt32 index)Public Function GetArrayAt(index As UInt32) As JsonArray
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The specified index.

Returns

The JsonArray at the specified index.

Attributes

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

Returns the item located at the specified index.

public IJsonValue GetAt(UInt32 index)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The integer index for the value to retrieve.

Returns

The JsonValue at the specified index.

Attributes

GetBoolean() GetBoolean() GetBoolean()

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

public bool GetBoolean()public bool GetBoolean()Public Function GetBoolean() As bool
Returns
bool bool bool

The Boolean value.

Attributes

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 bool GetBooleanAt(UInt32 index)public bool GetBooleanAt(UInt32 index)Public Function GetBooleanAt(index As UInt32) As bool
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The specified index.

Returns
bool bool bool

The Boolean value at the specified index.

Attributes

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)
Returns
System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator<T> System.Collections.Generic.IEnumerator<T>

An enumerator that can be used to iterate through the collection.

Attributes
See Also
System.Collections.Generic.IEnumerator<T>System.Collections.Generic.IEnumerator<T>System.Collections.Generic.IEnumerator<T>

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

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

public uint GetMany(UInt32 startIndex, IJsonValue[] items)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
startIndex
System.UInt32 System.UInt32 System.UInt32

The starting index.

items
Windows.Data.Json.IJsonValue[] Windows.Data.Json.IJsonValue[] Windows.Data.Json.IJsonValue[]

Returns items of the IJsonValue.

Returns
uint uint uint

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

Attributes

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
Returns
double double double

The number value.

Attributes

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(UInt32 index)public double GetNumberAt(UInt32 index)Public Function GetNumberAt(index As UInt32) As double
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The specified index.

Returns
double double double

The number value at the specified index.

Attributes

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
Returns
Attributes

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(UInt32 index)public JsonObject GetObjectAt(UInt32 index)Public Function GetObjectAt(index As UInt32) As JsonObject
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The specified index.

Returns

The JsonObject at the specified index.

Attributes

GetString() GetString() GetString()

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

public string GetString()public string GetString()Public Function GetString() As string
Returns
string string string

The String value.

Attributes

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

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

public string GetStringAt(UInt32 index)public string GetStringAt(UInt32 index)Public Function GetStringAt(index As UInt32) As string
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The specified index.

Returns
string string string

The String value at the specified index.

Attributes

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
Returns

The JsonArray view.

Attributes

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 Integer
Parameters
item
T T T

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

Returns
System.Int32 System.Int32 System.Int32

The index of item if found in the list; otherwise, -1.

Attributes

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 bool IndexOf(IJsonValue value, UInt32 index)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
value
IJsonValue IJsonValue IJsonValue

The IJsonValue to look up.

index
System.UInt32 System.UInt32 System.UInt32

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

Returns
bool bool bool

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

Attributes

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)
Parameters
index
System.Int32 System.Int32 System.Int32

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

item
T T T

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

Attributes
See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

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

Inserts a JsonValue into an array at the specified index.

public void InsertAt(UInt32 index, IJsonValue value)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
index
System.UInt32 System.UInt32 System.UInt32

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

value
IJsonValue IJsonValue IJsonValue

The IJsonValue object to insert.

Attributes

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(String input)public static JsonArray Parse(String input)Public Static Function Parse(input As String) As JsonArray
Parameters
input
System.String System.String System.String

The specified JSON string.

Returns
Attributes

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 @Windows.Data.Json.JsonObject.#ctor?text=JsonObject, this method requires the specified input string to be a valid JSON object value. When implemented on the subclass @Windows.Data.Json.JsonArray.#ctor?text=JsonArray, this method requires the specified input string to be a valid JSON array value. The original object state will be overwritten when @Windows.Data.Json.JsonObject.#ctor?text=JsonObject.@Windows.Data.Json.JsonValue.Parse(System.String)?text=Parse or @Windows.Data.Json.JsonArray.#ctor?text=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)

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)
Parameters
index
System.Int32 System.Int32 System.Int32

The zero-based index of the item to remove.

Attributes
See Also
System.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnlySystem.Collections.Generic.ICollection<T>.IsReadOnly

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

Removes the element at the specified index of the collection.

public void RemoveAt(UInt32 index)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The zero-based index of the element to remove.

Attributes

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

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
Attributes

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
Parameters
items
Windows.Data.Json.IJsonValue[] Windows.Data.Json.IJsonValue[] Windows.Data.Json.IJsonValue[]

The new collection items.

Attributes

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

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

public void SetAt(UInt32 index, IJsonValue value)This member is not implemented in C#This member is not implemented in VB.Net
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The index at which to set the value.

value
IJsonValue IJsonValue IJsonValue

The value to set.

Attributes

Stringify() Stringify() Stringify()

Returns the JSON representation of the encapsulated value.

public string Stringify()public string Stringify()Public Function Stringify() As string
Returns
string string string

A JSON representation of the encapsulated value.

Attributes

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

Returns the JSON representation of the encapsulated value.

public string ToString()public string ToString()Public Function ToString() As string
Returns
string string string

A JSON representation of the encapsulated value.

Attributes

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)

Parses the provided string into a JsonArray.

public static bool TryParse(String input, JsonArray result)public static bool TryParse(String input, JsonArray result)Public Static Function TryParse(input As String, result As JsonArray) As bool
Parameters
input
System.String System.String System.String

The specified string.

result
JsonArray JsonArray JsonArray

The new JsonArray object.

Returns
bool bool bool

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

Attributes

See Also