TJsonObject.AddObject#
Adiciona um objeto filho novo ou anexa um objeto existente.
Declarações#
function AddObject(const Name: String): TJsonObject;
function AddObject(const Name: String; const Value: TJsonObject): TJsonObject;Exemplo#
uses
Odisseia.Json;
var Root, Child, Attached: TJsonObject;
begin
Root := TJsonObject.Create;
Child := Root.AddObject('child');
Child.AddString('name', 'Ana');
Attached := TJsonObject.Create.AddInteger('id', 7);
Root.AddObject('attached', Attached);
Attached.AddBoolean('active', True);
WriteLn(Root.GetObject('child').GetString('name', ''));
WriteLn(BoolToStr(Root.GetObject('attached').GetBoolean('active', False)))
end.Resultado esperado: Ana e True.
A sobrecarga de dois argumentos retorna o objeto receptor e anexa o container por identidade. Ciclos são rejeitados. Uma chave existente é substituída.