Skip to content

Commit

Permalink
bug fix - root element
Browse files Browse the repository at this point in the history
  • Loading branch information
viniciussanchez committed Jul 24, 2024
1 parent ac43c24 commit df1cd1e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/DataSet.Serialize.pas
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ procedure TDataSetSerializeHelper.LoadFromJSON(const AJSONObject: TJSONObject; c
LJSONSerialize := TJSONSerialize.Create(AJSONObject, AOwns)
else
begin
LJSON := nil;
try
{$IF DEFINED(FPC)}
LJSON := AJSONObject.Find(ARootElement);
Expand All @@ -383,14 +384,17 @@ procedure TDataSetSerializeHelper.LoadFromJSON(const AJSONObject: TJSONObject; c
LJSON := AJSONObject.FindValue(ARootElement);
{$IFEND}
{$ENDIF}
if not Assigned(LJSON) then
raise Exception.Create('Root element not found!');
if LJSON.InheritsFrom(TJSONArray) then
LJSONSerialize := TJSONSerialize.Create(LJSON.Clone as TJSONArray, True)
if Assigned(LJSON) then
begin
if LJSON.InheritsFrom(TJSONArray) then
LJSONSerialize := TJSONSerialize.Create(LJSON.Clone as TJSONArray, True)
else
LJSONSerialize := TJSONSerialize.Create(LJSON.Clone as TJSONObject, True);
end
else
LJSONSerialize := TJSONSerialize.Create(LJSON.Clone as TJSONObject, True);
LJSONSerialize := TJSONSerialize.Create(AJSONObject, AOwns);
finally
if AOwns then
if AOwns and Assigned(LJSON) then
AJSONObject.Free;
end;
end;
Expand Down

0 comments on commit df1cd1e

Please sign in to comment.