#1 2020-09-22 19:39:35

Hafedh TRIMECHE
Member
Registered: 2016-09-18
Posts: 32

Char/WideChar JSON conversion problem

The Char/WideChar record field is converted to ASCII code instead of its content:

type
  TCharRecord=
  record
    Value : Char;
  end;
procedure SynJSON;
var
  CharRecord : TCharRecord;
  sJSON      : string;
begin
  CharRecord.Value := 'Y';
  TTextWriter.RegisterCustomJSONSerializerSetOptions(TypeInfo(TCharRecord),[soWriteIgnoreDefault],True);
  sJSON := string(RecordSaveJSON(CharRecord,TypeInfo(TCharRecord),True));
  Memo1.Lines.Text := sJSON;
end;

giving {"Value":89} as result instead of {"Value":"Y"}

Would an option be considered to handle such conversion?

Offline

#2 2020-09-23 07:36:31

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

Re: Char/WideChar JSON conversion problem

This is a limitation of the current serializer.
You need a string or a RawUTF8 to have a JSON string emitted.

Offline

Board footer

Powered by FluxBB