#1 2016-10-07 16:35:44

jars
Member
Registered: 2015-05-15
Posts: 29

Is there a way to serialize static arrays

I need to convert to JSON this static arrays and  don't known how.

type
  TCCConfig = packed record
    Version: string[10];
    DNDReasons: array[1..15] of string[15];
  end;

const
  __TCCConfig = 'Version string[10]  DNDReason array[1..15] of string[15]';
....

// then use move to fill this record with lData stream.
var
  CCConfig: TCCConfig;
  CurOff: Integer;
begin
  TTextWriter.RegisterCustomJSONSerializerFromText(TypeInfo(TCCConfig),            <-------------  ERROR
  __TMCCConfig).Options := [soReadIgnoreUnknownFields,soWriteHumanReadable];

   CurOff := 1;
  system.move(lData[CurOff], CCConfig, sizeof(CCConfig));

Offline

#2 2016-10-07 19:13:52

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

Re: Is there a way to serialize static arrays

For such arrays with shortstring, use base64 encoding...
If you expect JSON serialization, use real string fields.

Offline

#3 2016-10-11 11:59:22

jars
Member
Registered: 2015-05-15
Posts: 29

Re: Is there a way to serialize static arrays

Thanks Ab but can't understand. Have you an example?

Offline

#4 2016-10-11 12:27:34

oz
Member
Registered: 2015-09-02
Posts: 98

Re: Is there a way to serialize static arrays

Just have a look at: http://synopse.info/files/html/Synopse% … #TITLE_231 for a starting point...

Offline

Board footer

Powered by FluxBB