JsonArray JsonArray JsonArray Class

Definition

Represents a JSON array.

@Windows.Data.Json.JsonArray.#ctor inherits the IVector<T> and IIterable<T> interfaces, which provide methods to iterate through the elements in the array and update its contents.

public sealed class JsonArraypublic sealed class JsonArrayPublic NotInheritable Class JsonArray
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() JsonArray()

Creates a new JsonArray object that represents a JSON array.

public JsonArray()public New()Public Sub New()public JsonArray()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Properties

Size Size Size Size

Gets the size (count) of the array.

public uint Size { get; }public uint Size { get; }Public ReadOnly Property Size As uintpublic uint Size { get; }
Value
uint uint uint

The count of items in the array.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 JsonValueTypepublic JsonValueType ValueType { get; }
Value
JsonValueType JsonValueType JsonValueType

The JSON value type.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Methods

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

Adds a new item to the array.

public void Append(IJsonValue value)public void Append(IJsonValue value)Public Function Append(value As IJsonValue) As voidpublic void Append(IJsonValue value)
Parameters
value
IJsonValue IJsonValue IJsonValue

The new item to add.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

Removes all items from the collection.

public void Clear()public void Clear()Public Function Clear() As voidpublic void Clear()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

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

public IIterator<IJsonValue> First()public IIterator<IJsonValue> First()Public Function First() As IIterator( Of IJsonValue )public IIterator<IJsonValue> First()
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
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 JsonArraypublic JsonArray GetArray()
Returns
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

The specified index.

Returns

The JsonArray at the specified index.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

Returns the item located at the specified index.

public IJsonValue GetAt(UInt32 index)public IJsonValue GetAt(UInt32 index)Public Function GetAt(index As UInt32) As IJsonValuepublic IJsonValue GetAt(UInt32 index)
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The integer index for the value to retrieve.

Returns

The JsonValue at the specified index.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

GetBoolean() 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 boolpublic bool GetBoolean()
Returns
bool bool bool

The Boolean value.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

The specified index.

Returns
bool bool bool

The Boolean value at the specified index.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 uint GetMany(UInt32 startIndex, IJsonValue[] items)public uint GetMany(UInt32 startIndex, IJsonValue[] items)Public Function GetMany(startIndex As UInt32, items As IJsonValue[]) As uintpublic uint GetMany(UInt32 startIndex, IJsonValue[] items)
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
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 doublepublic double GetNumber()
Returns
double double double

The number value.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

The specified index.

Returns
double double double

The number value at the specified index.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 JsonObjectpublic JsonObject GetObject()
Returns
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

The specified index.

Returns

The JsonObject at the specified index.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

GetString() 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 stringpublic string GetString()
Returns
string string string

The String value.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 string GetStringAt(UInt32 index)public string GetStringAt(UInt32 index)Public Function GetStringAt(index As UInt32) As stringpublic string GetStringAt(UInt32 index)
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The specified index.

Returns
string string string

The String value at the specified index.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

Gets a JsonArray view.

public IVectorView<IJsonValue> GetView()public IVectorView<IJsonValue> GetView()Public Function GetView() As IVectorView( Of IJsonValue )public IVectorView<IJsonValue> GetView()
Returns

The JsonArray view.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 bool IndexOf(IJsonValue value, UInt32 index)public bool IndexOf(IJsonValue value, UInt32 index)Public Function IndexOf(value As IJsonValue, index As UInt32) As boolpublic bool IndexOf(IJsonValue value, UInt32 index)
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
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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(UInt32 index, IJsonValue value)public void InsertAt(UInt32 index, IJsonValue value)Public Function InsertAt(index As UInt32, value As IJsonValue) As voidpublic void InsertAt(UInt32 index, IJsonValue value)
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
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 TryParse(String, JsonObject) is a recommended alternative. A TryParse(String, JsonArray) 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 JsonArraypublic static JsonArray Parse(String input)
Parameters
input
System.String System.String System.String

The specified JSON string.

Returns
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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(String) 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, this method requires the specified input string to be a valid JSON object value. When implemented on the subclass @Windows.Data.Json.JsonArray.#ctor, 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.@Windows.Data.Json.JsonValue.Parse(System.String) or @Windows.Data.Json.JsonArray.#ctor.@Windows.Data.Json.JsonValue.Parse(System.String) succeeds. If Parse(String) fails, the object state remains intact.

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

Removes the element at the specified index of the collection.

public void RemoveAt(UInt32 index)public void RemoveAt(UInt32 index)Public Function RemoveAt(index As UInt32) As voidpublic void RemoveAt(UInt32 index)
Parameters
index
System.UInt32 System.UInt32 System.UInt32

The zero-based index of the element to remove.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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()public void RemoveAtEnd()Public Function RemoveAtEnd() As voidpublic void RemoveAtEnd()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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)public void ReplaceAll(IJsonValue[] items)Public Function ReplaceAll(items As IJsonValue[]) As voidpublic void ReplaceAll(IJsonValue[] items)
Parameters
items
Windows.Data.Json.IJsonValue[] Windows.Data.Json.IJsonValue[] Windows.Data.Json.IJsonValue[]

The new collection items.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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(UInt32 index, IJsonValue value)public void SetAt(UInt32 index, IJsonValue value)Public Function SetAt(index As UInt32, value As IJsonValue) As voidpublic void SetAt(UInt32 index, IJsonValue value)
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
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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

Returns the JSON representation of the encapsulated value.

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

A JSON representation of the encapsulated value.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 string ToString()public string ToString()Public Function ToString() As stringpublic string ToString()
Returns
string string string

A JSON representation of the encapsulated value.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

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 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 boolpublic static bool TryParse(String input, JsonArray result)
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
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)