Vai al contenuto principale

TJsonArray

Classe

type TJsonArray = class(TJson)

Rappresenta un array JSON. Contiene 0 o più elementi accessibili tramite indice.

Caratteristiche

ElementCount: Integer in lettura e scrittura;

Imposta/restituisce il numero di elementi dell'array.

Elementi[Indice: Intero]: TJson lettura-scrittura; predefinito;

Imposta/restituisce l'elemento specificato dell'array. L'indice deve essere compreso tra 0 e ElementCount - 1.

A [Indice: Intero]: TJson;

Consente di recuperare o impostare un elemento dell'array se si tratta effettivamente di un TJsonArray e l'indice è valido. Altrimenti viene generata un'eccezione.

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;

Restituisce l'elemento dell'array specificato se l'indice è valido e il tipo richiesto corrisponde al contenuto.

Metodi

costruttore Create(ElementCount: Integer = 0);

Crea un'istanza di TJsonArray.

funzione AppendArray(ElementCount: Integer): TJsonArray;

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

procedura AppendFalse;

funzione AppendJson(Value: TJson): TJson;

procedura AppendNull;

procedura AppendNumber(Value: Double);

funzione AppendObject: TJsonObject;

procedura AppendString(const Value: WideString);

procedura AppendTrue;

I metodi Append aumentano la dimensione dell'array di 1 e inseriscono il nuovo elemento alla fine. AppendArray, AppendJson e AppendObject restituiscono istanze degli elementi appena creati per ulteriori operazioni.

procedura Delete(Index: Integer);

È stato rimosso l'elemento dell'array all'indice, riducendo la dimensione dell'array di 1.

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

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

procedura InsertFalse(Index: Integer);

funzione 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);

I metodi Insert aumentano di uno la dimensione dell'array, inserendo il nuovo elemento all'indice indicato. Le funzioni InsertArray, InsertJson e InsertObject restituiscono istanze degli elementi appena creati per ulteriori operazioni.

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

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

procedura SetFalse(Index: Integer);

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

procedura SetNull(Index: Integer);

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

function SetObject(Index: Integer): TJsonObject;

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

procedure SetTrue(Index: Integer);

I metodi Set convertono l'elemento all'indice indicato nel tipo e nel valore specificati. SetArray, SetJson e SetObject restituiscono istanze degli elementi appena modificati per ulteriori operazioni.

procedura Swap(Indice1, Indice2: Intero);

Scambia gli elementi specificati dell'array;

Esempio

jArray = TJsonArray.Create(0) 'Crea un array vuoto
showmessage(jarray.ElementCount) 'Visualizza 0

jArray.AppendTrue 'jArray.Elements[0] ora esiste e contiene True
showmessage(jArray.ElementCount) 'Visualizza 1

jArray.InsertFalse(0) 'jArray.Elements[0] ora esiste e contiene False. jArray.Elements[1] contiene True
showmessage(jArray.ElementCount) 'Visualizza 2

jArray.Delete(0) 'Il vecchio elemento jArray.Elements[0] è stato eliminato. jArray.Elements[0] ora contiene True
showmessage(jArray.ElementCount) 'Visualizza 1 |