Pular para o conteúdo principal

TJsonArray

Class

type TJsonArray = class(TJson)

Represents a JSON array. Contains 0 or more elements accessed by index.

Properties

ElementCount: Integer read write;

Set/return the number of elements in the array.

Elements[Index: Integer]: TJson read write; default;

Set/return the specified array element. Index must be between 0 and ElementCount - 1.

At[Index: Integer]: TJson;

Allows getting/setting an array element if it is actually a TJsonArray and the index is valid. Otherwise throws an exception.

NullAt[Index: Integer]: TJsonNull read;

FalseAt[Index: Integer]: TJsonFalse read;

TrueAt[Index: Integer]: TJsonTrue read;

ObjectAt[Index: Integer]: TJsonObject read;

StringAt[Index: Integer]: TJsonString read;

ArrayAt[Index: Integer]: TJsonArray read;

NumberAt[Index: Integer]: TJsonNumber read;

Returns the specified array element if the index is valid, and the type requested matches the contents.

Methods

constructor Create(ElementCount: Integer = 0);

Creates a TJsonArray instance.

function AppendArray(ElementCount: Integer): TJsonArray;

procedure AppendDateTime(const Value: TDateTime; Offset: Integer = 0);

procedure AppendFalse;

function AppendJson(Value: TJson): TJson;

procedure AppendNull;

procedure AppendNumber(Value: Double);

function AppendObject: TJsonObject;

procedure AppendString(const Value: WideString);

procedure AppendTrue;

The Append methods increase the size of the array by 1, and put the new element at the end. AppendArray, AppendJson, and AppendObject return instances of the newly created elements for further manipulation.

procedure Delete(Index: Integer);

Removed the array element at Index, reducing the size of the array by 1.

function InsertArray(Index: Integer; ElementCount: Integer): TJsonArray;

procedure InsertDateTime(Index: Integer; const Value: TDateTime; Offset: Integer = 0);

procedure InsertFalse(Index: Integer);

function InsertJson(Index: Integer; Value: TJson): TJson;

procedure InsertNull(Index: Integer);

procedure InsertNumber(Index: Integer; Value: Double);

function InsertObject(Index: Integer): TJsonObject;

procedure InsertString(Index: Integer; const Value: WideString);

procedure InsertTrue(Index: Integer);

The Insert methods increase the size of the array by one, putting the new element at the indicated index. InsertArray, InsertJson, and InsertObject return instances of the newly created elements for further manipulation.

function SetArray(Index: Integer; ElementCount: Integer): TJsonArray;

procedure SetDateTime(Index: Integer; const Value: TDateTime; Offset: Integer = 0);

procedure SetFalse(Index: Integer);

function SetJson(Index: Integer; Value: TJson): TJson;

procedure SetNull(Index: Integer);

procedure SetNumber(Index: Integer; Value: Double);

function SetObject(Index: Integer): TJsonObject;

procedure SetString(Index: Integer; const Value: WideString);

procedure SetTrue(Index: Integer);

The Set methods convert the element at the indicated index to the specified type and value. SetArray, SetJson, and SetObject return instances of the newly modified elements for further manipulation.

procedure Swap(Index1, Index2: Integer);

Swaps the specified array elements;

Example

jArray = TJsonArray.Create(0) 'Creates an empty array
showmessage(jarray.ElementCount) 'Displays 0

jArray.AppendTrue 'jArray.Elements[0] now exists and contains True
showmessage(jArray.ElementCount) 'Displays 1

jArray.InsertFalse(0) 'jArray.Elements[0] now exists and contains False. jArray.Elements[1] contains True
showmessage(jArray.ElementCount) 'Displays 2

jArray.Delete(0) 'old jArray.Elements[0] deleted. jArray.Elements[0] now contains True
showmessage(jArray.ElementCount) 'Displays 1 |