Einzelnen Beitrag anzeigen

Der schöne Günther

Registriert seit: 6. Mär 2013
6.110 Beiträge
 
Delphi 10 Seattle Enterprise
 
#3

AW: einfaches JSON Beispiel

  Alt 16. Mär 2022, 07:10
Alternative:

Delphi-Quellcode:
program Project1;

{$R *.res}

uses System.SysUtils, System.JSON;

const
   input = '{"status":"success","data":{"status":"online","benchmarking":"TEST","online":"connected"}}';
var
   jsonObj: TJsonObject;
   status: String;
begin
   jsonObj := TJSONObject.ParseJSONValue(input) as TJsonObject;
   if(not Assigned(jsonObj)) then
      WriteLn('input is no valid json object')
   else
      try
         status := jsonObj.GetValue<String>('data.status');
         WriteLn('status is ', status);
      finally
         jsonObj.Destroy();
      end;
end.
  Mit Zitat antworten Zitat