TJsonArray
Turma
type TJsonArray = class(TJson)
Representa uma matriz JSON. Contém 0 ou mais elementos acessados por índice.
Características
ElementCount: Integer de leitura e escrita;
Definir/retornar o número de elementos na matriz.
Elements[Índice: Inteiro]: TJson leitura e gravação; padrão;
Definir/recuperar o elemento da matriz especificado. O índice deve estar compreendido entre 0 e ElementCount - 1.
Em [Índice: Inteiro]: TJson;
Permite obter/definir um elemento de uma matriz, desde que esta seja efetivamente uma TJsonArray e o índice seja válido. Caso contrário, é lançada uma exceção.
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;
Devolve o elemento da matriz especificado se o índice for válido e o tipo solicitado corresponder ao conteúdo.
Métodos
construtor Create(ElementCount: Integer = 0);
Cria uma instância de TJsonArray.
função AppendArray(ElementCount: Integer): TJsonArray;
procedimento AppendDateTime(const Value: TDateTime; Offset: Integer = 0);
procedimento AppendFalse;
função AppendJson(Value: TJson): TJson;
procedimento AppendNull;
procedimento AppendNumber(Value: Double);
função AppendObject: TJsonObject;
procedimento AppendString(const Value: WideString);
procedimento AppendTrue;
Os métodos Append aumentam o tamanho da matriz em 1 e inserem o novo elemento no final. Os métodos AppendArray, AppendJson e AppendObject devolvem instâncias dos elementos recém-criados para posterior manipulação.
procedimento Delete(Índice: Inteiro);
Removido o elemento da matriz no índice, reduzindo o tamanho da matriz em 1.
função InsertArray(Index: Integer; ElementCount: Integer): TJsonArray;
procedimento InsertDateTime(Index: Integer; const Value: TDateTime; Offset: Integer = 0);
procedimento InsertFalse(Index: Integer);
função 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);
Os métodos Insert aumentam o tamanho da matriz em um, inserindo o novo elemento no índice indicado. As funções InsertArray, InsertJson e InsertObject devolvem instâncias dos elementos recém-criados para posterior manipulação.
função SetArray(Index: Integer; ElementCount: Integer): TJsonArray;
procedimento SetDateTime(Index: Integer; const Value: TDateTime; Offset: Integer = 0);
procedimento SetFalse(Index: Integer);
função SetJson(Index: Integer; Value: TJson): TJson;
procedimento SetNull(Index: Integer);
procedimento SetNumber(Index: Integer; Value: Double);
função SetObject(Index: Integer): TJsonObject;
procedimento SetString(Index: Integer; const Value: WideString);
procedimento SetTrue(Index: Integer);
Os métodos Set convertem o elemento no índice indicado para o tipo e valor especificados. As funções SetArray, SetJson e SetObject devolvem instâncias dos elementos recém-modificados para posterior manipulação.
procedimento Swap(Índice1, Índice2: Inteiro);
Troca os elementos especificados da matriz;
Exemplo
jArray = TJsonArray.Create(0) 'Cria uma matriz vazia
showmessage(jarray.ElementCount) 'Exibe 0
jArray.AppendTrue 'jArray.Elements[0] existe agora e contém True
showmessage(jArray.ElementCount) 'Exibe 1
jArray.InsertFalse(0) 'jArray.Elements[0] existe agora e contém False. jArray.Elements[1] contém True
showmessage(jArray.ElementCount) 'Exibe 2
jArray.Delete(0) 'O antigo jArray.Elements[0] foi eliminado. jArray.Elements[0] contém agora True
showmessage(jArray.ElementCount) 'Exibe 1 |