Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
JSON AppendArray2 Example
Demonstrates the AppendArray2 function.Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.JsonArray,
Chilkat.JsonObject;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
json: TJsonObject;
jarr: TJsonArray;
begin
json := TJsonObject.Create;
json.Load('{ "name": "John", "marbles": 100 }');
// Append an empty array named "xyz"
jarr := TJsonArray.Create;
json.AppendArray2('xyz',jarr);
WriteLn(json.Emit());
// Expected output is: {"name":"John","marbles":100,"xyz":[]}
// Add elements to the array.
jarr.AddStringAt(-1,'hello');
jarr.AddIntAt(-1,256);
WriteLn(json.Emit());
// Expected output is: {"name":"John","marbles":100,"xyz":["hello",256]}
json.Free;
jarr.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.