#1 2020-06-23 03:59:57

ertank
Member
Registered: 2016-03-16
Posts: 168

Help needed with custom json text definition - Delphi 7

Hello,

I am using Delphi 7 and latest available version of Synopse from GitHub. Just removed all SynCommons.pas files from my system and have just a single copy.

Registering a custom json text writer fails for me. Details are as following:

type
  TTicker = packed record
    symbol: RawUTF8;
    highPrice: Double;
    lowPrice: Double;
  end;
  TTickers = Array of TTicker;

const
  __TTickers = '[symbol RawUTF8 highPrice Double lowPrice Double]';


initialization
  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TTickers), __TTickers);
end;

I am getting error saying:

TTicker text definition is not accurate, or the type has not been defined as packed record: RTTI size is 20 bytes but text definition covers 0 bytes

I cannot see where I am doing it wrong.

Any help is appreciated.

Thanks & regards,
Ertan

Offline

#2 2020-06-23 07:37:52

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

Re: Help needed with custom json text definition - Delphi 7

Try

__TTickers = 'symbol:RawUTF8 highPrice,lowPrice:Double';

The embrassing [  ] are not meant to be there - they are allowed only for nested arrays.
Please check the docs and samples.

Offline

#3 2020-06-23 09:51:01

ertank
Member
Registered: 2016-03-16
Posts: 168

Re: Help needed with custom json text definition - Delphi 7

Missed that point in samples.
Thanks for clarifying.

Offline

Board footer

Powered by FluxBB