Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Get JSON Details from the Last REST Operation

See more REST Examples

Demonstrates Rest.GetLastJsonData, which copies operation-specific diagnostic or result information from the most recently completed method into a JsonObject. Many methods produce no JSON, in which case the object is empty.

Tip: Code to parse the returned JSON can be generated with Chilkat's online tool at https://tools.chilkat.io/jsonParse.

Background. Some Chilkat operations expose additional structured information as JSON. GetLastJsonData provides access to that information after an operation completes.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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.Rest,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  rest: TRest;
  bTls: Boolean;
  bAutoReconnect: Boolean;
  json: TJsonObject;
  jsonStr: string;

begin
  success := False;

  rest := TRest.Create;
  bTls := True;
  bAutoReconnect := True;
  success := rest.Connect('example.com',443,bTls,bAutoReconnect);
  if (success = False) then
    begin
      WriteLn(rest.LastErrorText);
      Exit;
    end;

  //  Copy operation-specific diagnostic or result information from the most recent method (here the
  //  Connect call) into a JsonObject.  Many methods produce no JSON, in which case the object is empty.
  json := TJsonObject.Create;
  rest.GetLastJsonData(json);

  json.EmitCompact := False;
  jsonStr := json.Emit();
  WriteLn(jsonStr);
  //  JSON parsing code for this result can be generated at Chilkat's online tool:
  //  https://tools.chilkat.io/jsonParse


  rest.Free;
  json.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.