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

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 New()Public Sub New()public JsonArray()

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; }

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

    Property Value

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

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

    Removes all items from the collection.

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

  • 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

  • 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

  • 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

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

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

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

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

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

  • 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

  • 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

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

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

  • 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

  • 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

    Returns

    • bool
      bool
      bool

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

  • 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

  • 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

    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.

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

  • 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

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

    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.

    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

    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.ActivatableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute

Details

Assembly

Windows.Data.Json.dll