You are not logged in.
Pages: 1
Hello,
Using Delphi 10.2. Target is Win32 executable.
mORMot commit version is 1.18.3599
I have following definitions:
type
TItem = packed record
FNo: string;
FDescription: string;
FUoM: string;
FPrice: Double;
FStock: Double;
end;
TItems = TArray<TItem>;
I am receiving below json string from a webservice:
[{"FNo":"LSU-8","FDescription":"8\"100W mellemtone i højttaler","FUoM":"STK","FPrice":21,"FStock":15}]
My code for RecordLoadJSON is as follows:
var
AItems: TItems;
Json: WideString;
AJson: string;
begin
Response := GetItem(Json, Error);
if Response <> RESPONSE_OK then
begin
ShowMessage('Soap error: ' + Error);
Exit();
end;
AJson := Json; // Convert WideString to string as I am not able to find where the error is
if not RecordLoadJSON(AItems, RawUTF8(AJson), TypeInfo(TItems)) then
begin
ShowMessage('Json error: Cannot decode json into record. Json string will be printed in Memo');
Memo1.Lines.Text := AJson;
Exit();
end;
end;
Above code always gives me "Cannot decode json..." error displayed for provided json string.
It is very late and I maybe missing something obvious. Just wanted some different eyes to check it out.
I appreciate any help.
Thanks.
-Ertan
Offline
You should use DynArrayLoadJSON:
var
AItems: TItems;
AJson: RawUTF8;
begin
AJson := '[{"FNo":"LSU-8","FDescription":"8\"100W mellemtone i højttaler","FUoM":"STK","FPrice":21,"FStock":15}]';
DynArrayLoadJSON(AItems, @AJson[1], TypeInfo(TItems));
Offline
Hello igors233, Thank you. That must be it that I could not see at late night hours. Appreciated.
Offline
Pages: 1