Another method to do JSON to Object.
unit StructureTestTypes;
interface
uses
REST.Json, System.SysUtils;
type
TStructure = class(TObject) // '{"RESULT":200, "IDLIST":[1,2,3,4,5]}'
private
FIDLIST: TArray<Integer>;
FRESULT: integer;
public
constructor Create; virtual;
destructor Destroy; override;
property RESULT: integer read FRESULT write FRESULT;
property IDLIST: TArray<Integer> read FIDLIST write FIDList;
end;
implementation
{ TStructure }
constructor TStructure.Create;
begin
SetLength(FIDLIST, 0);
end;
destructor TStructure.Destroy;
begin
SetLength(FIDLIST, 0);
inherited;
end;
end.
Test Program:
program JsonStructureTest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
REST.Json,
StructureTestTypes in 'StructureTestTypes.pas';
var
Test: TStructure;
begin
Test := TJson.JsonToObject<TStructure>('{"RESULT":200, "IDLIST":[1,2,3,4,5]}']);
try
try
Writeln('Result: ', Test.RESULT);
Write('IDList:');
for var i in Test.IDLIST
do Write(' ', i );
Writeln;
except
on E: Exception
do Writeln(E.ClassName, ': ', E.Message);
end;
finally
Test.Free;
Writeln;
Write('Press Enter: ');
Readln;
end;
end.