JsonArray JsonArray JsonArray Class

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.

Syntax

Declaration

public sealed class JsonArraypublic sealed class JsonArrayPublic NotInheritable Class JsonArray

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 summary

Creates a new JsonArray object that represents a JSON array.

Properties summary

Gets the size (count) of the array.

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

Methods summary

Adds a new item to the array.

Removes all items from the collection.

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

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

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

Returns the item located at the specified index.

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

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

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

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

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

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

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

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

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

Gets a JsonArray view.

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

Inserts a JsonValue into an array at the specified index.

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(System.String,Windows.Data.Json.JsonObject) is a recommended alternative. A TryParse(System.String,Windows.Data.Json.JsonArray) call will return a boolean value to indicate success or failure and, if successful, the resultant JsonArray.

Removes the element at the specified index of the collection.

Removes the last item in the array.

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

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

Returns the JSON representation of the encapsulated value.

Returns the JSON representation of the encapsulated value.

Parses the provided string into a JsonArray.

Constructors

  • JsonArray()
    JsonArray()
    JsonArray()
    JsonArray()

    Creates a new JsonArray object that represents a JSON array.

    public JsonArray()public JsonArray()Public Function JsonArray() As

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 uint

    Property Value

    • 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

    Property Value

Methods

  • Append(Windows.Data.Json.IJsonValue)
    Append(Windows.Data.Json.IJsonValue)
    Append(Windows.Data.Json.IJsonValue)
    Append(Windows.Data.Json.IJsonValue)

    Adds a new item to the array.

    public void Append(Windows.Data.Json.IJsonValue)public void Append(Windows.Data.Json.IJsonValue)Public Function Append(Windows.Data.Json.IJsonValue) As void

    Parameters

  • Clear()
    Clear()
    Clear()
    Clear()

    Removes all items from the collection.

    public void Clear()public void Clear()Public Function Clear() As void
  • 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 )

    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

    Returns

  • GetArrayAt(System.UInt32)
    GetArrayAt(System.UInt32)
    GetArrayAt(System.UInt32)
    GetArrayAt(System.UInt32)

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

    public JsonArray GetArrayAt(System.UInt32)public JsonArray GetArrayAt(System.UInt32)Public Function GetArrayAt(System.UInt32) As JsonArray

    Parameters

    • index
      System.UInt32
      System.UInt32
      System.UInt32

      The specified index.

    Returns

  • GetAt(System.UInt32)
    GetAt(System.UInt32)
    GetAt(System.UInt32)
    GetAt(System.UInt32)

    Returns the item located at the specified index.

    public IJsonValue GetAt(System.UInt32)public IJsonValue GetAt(System.UInt32)Public Function GetAt(System.UInt32) As IJsonValue

    Parameters

    • index
      System.UInt32
      System.UInt32
      System.UInt32

      The integer index for the value to retrieve.

    Returns

  • 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 bool

    Returns

    • bool
      bool
      bool

      The Boolean value.

  • GetBooleanAt(System.UInt32)
    GetBooleanAt(System.UInt32)
    GetBooleanAt(System.UInt32)
    GetBooleanAt(System.UInt32)

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

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

  • GetMany(System.UInt32,Windows.Data.Json.IJsonValue[])
    GetMany(System.UInt32,Windows.Data.Json.IJsonValue[])
    GetMany(System.UInt32,Windows.Data.Json.IJsonValue[])
    GetMany(System.UInt32,Windows.Data.Json.IJsonValue[])

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

    public uint GetMany(System.UInt32,Windows.Data.Json.IJsonValue[])public uint GetMany(System.UInt32,Windows.Data.Json.IJsonValue[])Public Function GetMany(System.UInt32,Windows.Data.Json.IJsonValue[]) As uint

    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.

  • 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

    Returns

    • double
      double
      double

      The number value.

  • GetNumberAt(System.UInt32)
    GetNumberAt(System.UInt32)
    GetNumberAt(System.UInt32)
    GetNumberAt(System.UInt32)

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

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

  • 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

    Returns

  • GetObjectAt(System.UInt32)
    GetObjectAt(System.UInt32)
    GetObjectAt(System.UInt32)
    GetObjectAt(System.UInt32)

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

    public JsonObject GetObjectAt(System.UInt32)public JsonObject GetObjectAt(System.UInt32)Public Function GetObjectAt(System.UInt32) As JsonObject

    Parameters

    • index
      System.UInt32
      System.UInt32
      System.UInt32

      The specified index.

    Returns

  • 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 string

    Returns

    • string
      string
      string

      The String value.

  • GetStringAt(System.UInt32)
    GetStringAt(System.UInt32)
    GetStringAt(System.UInt32)
    GetStringAt(System.UInt32)

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

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

  • GetView()
    GetView()
    GetView()
    GetView()

    Gets a JsonArray view.

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

    Returns

  • IndexOf(Windows.Data.Json.IJsonValue,System.UInt32)
    IndexOf(Windows.Data.Json.IJsonValue,System.UInt32)
    IndexOf(Windows.Data.Json.IJsonValue,System.UInt32)
    IndexOf(Windows.Data.Json.IJsonValue,System.UInt32)

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

    public bool IndexOf(Windows.Data.Json.IJsonValue,System.UInt32)public bool IndexOf(Windows.Data.Json.IJsonValue,System.UInt32)Public Function IndexOf(Windows.Data.Json.IJsonValue,System.UInt32) As bool

    Parameters

    Returns

    • bool
      bool
      bool

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

  • InsertAt(System.UInt32,Windows.Data.Json.IJsonValue)
    InsertAt(System.UInt32,Windows.Data.Json.IJsonValue)
    InsertAt(System.UInt32,Windows.Data.Json.IJsonValue)
    InsertAt(System.UInt32,Windows.Data.Json.IJsonValue)

    Inserts a JsonValue into an array at the specified index.

    public void InsertAt(System.UInt32,Windows.Data.Json.IJsonValue)public void InsertAt(System.UInt32,Windows.Data.Json.IJsonValue)Public Function InsertAt(System.UInt32,Windows.Data.Json.IJsonValue) As void

    Parameters

  • Parse(System.String)
    Parse(System.String)
    Parse(System.String)
    Parse(System.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(System.String,Windows.Data.Json.JsonObject) is a recommended alternative. A TryParse(System.String,Windows.Data.Json.JsonArray) call will return a boolean value to indicate success or failure and, if successful, the resultant JsonArray.

    public static JsonArray Parse(System.String)public static JsonArray Parse(System.String)Public Static Function Parse(System.String) As JsonArray

    Parameters

    • input
      System.String
      System.String
      System.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(System.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(System.String) fails, the object state remains intact.

  • RemoveAt(System.UInt32)
    RemoveAt(System.UInt32)
    RemoveAt(System.UInt32)
    RemoveAt(System.UInt32)

    Removes the element at the specified index of the collection.

    public void RemoveAt(System.UInt32)public void RemoveAt(System.UInt32)Public Function RemoveAt(System.UInt32) As void

    Parameters

    • index
      System.UInt32
      System.UInt32
      System.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()public void RemoveAtEnd()Public Function RemoveAtEnd() As void
  • ReplaceAll(Windows.Data.Json.IJsonValue[])
    ReplaceAll(Windows.Data.Json.IJsonValue[])
    ReplaceAll(Windows.Data.Json.IJsonValue[])
    ReplaceAll(Windows.Data.Json.IJsonValue[])

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

    public void ReplaceAll(Windows.Data.Json.IJsonValue[])public void ReplaceAll(Windows.Data.Json.IJsonValue[])Public Function ReplaceAll(Windows.Data.Json.IJsonValue[]) As void

    Parameters

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

      The new collection items.

  • SetAt(System.UInt32,Windows.Data.Json.IJsonValue)
    SetAt(System.UInt32,Windows.Data.Json.IJsonValue)
    SetAt(System.UInt32,Windows.Data.Json.IJsonValue)
    SetAt(System.UInt32,Windows.Data.Json.IJsonValue)

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

    public void SetAt(System.UInt32,Windows.Data.Json.IJsonValue)public void SetAt(System.UInt32,Windows.Data.Json.IJsonValue)Public Function SetAt(System.UInt32,Windows.Data.Json.IJsonValue) As void

    Parameters

  • Stringify()
    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.

    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 string

    Returns

    • 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(System.String,Windows.Data.Json.JsonArray)
    TryParse(System.String,Windows.Data.Json.JsonArray)
    TryParse(System.String,Windows.Data.Json.JsonArray)
    TryParse(System.String,Windows.Data.Json.JsonArray)

    Parses the provided string into a JsonArray.

    public static bool TryParse(System.String,Windows.Data.Json.JsonArray)public static bool TryParse(System.String,Windows.Data.Json.JsonArray)Public Static Function TryParse(System.String,Windows.Data.Json.JsonArray) As bool

    Parameters

    Returns

    • bool
      bool
      bool

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

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.ActivatableAttribute

Details

Assembly

Windows.Data.Json.dll