#1 2017-07-13 07:39:35

squirrel
Member
Registered: 2015-08-13
Posts: 155

Different Json results between Delphi 7 and XE3

Are there any conditional defines that must be set for Delphi 7?  I noticed that the results for TDocVariantData.ToJSON() differs between Delphi 7 and XE3.

Sample code:

procedure TForm1.FormCreate(Sender: TObject);
type
  TListItem = record
    Name: string;
    Value: integer;
  end;
  TListItems = Array of TListItem;
var
  Source: TDocVariantData;
  Data: TListItems;
  DataStr: RawUtf8;
begin
  SetLength(Data, 2);
  Data[0].Name := 'Name1';  Data[0].Value := 0;
  Data[1].Name := 'Name2';  Data[1].Value := 1;

  Source.InitFromTypeInfo(Data, TypeInfo(TListItems), true, []);
  DataStr := source.ToJSON();
  Memo1.Lines.Add(DataStr);
end;

In XE3, this produces:

[{"Name":"Name1","Value":0},{"Name":"Name2","Value":1}]

In Delphi 7, this produces:

["Name1",""]

Offline

#2 2017-07-13 07:52:02

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: Different Json results between Delphi 7 and XE3

You need to register the record information with text, since there is no RTTI for records in Delphi 7.
See https://synopse.info/files/html/Synopse … #TITLE_234
and the record should be marked as "packed".

Offline

Board footer

Powered by FluxBB