我正在尝试在运行时将一个对象转换为JSON,但是我遇到了不足的RTTI错误。 这个对象是:
{$M+}
{$TYPEINFO ON}
{$METHODINFO ON}
{$RTTI EXPLICIT METHODS([vcPublic, vcPublished]) PROPERTIES([vcPublic, vcPublished])}
TMyPacket = class(TObject)
Private
FID: TGUID;
FToIP: string;
FToPort: integer;
FSent: boolean;
FSentAt: TDateTime;
FAck: boolean;
FTimeOut: Cardinal;
FDataToSendSize: UINT64;
FDataToSend: AnsiString;
public
constructor create;
destructor free;
published
property ID: TGUID read FID write FID;
property ToIP: string read FToIP write FToIP;
property ToPort: integer read FToPort write FToPort;
property Sent: boolean read FSent write FSent;
property SentAt: TDateTime read FSentAt write FSentAt;
property Ack: boolean read FAck write FAck;
property TimeOut: Cardinal read FTimeOut write FTimeOut;
property DataToSend: AnsiString read FDataToSend write FDataToSend;
end;
代码后面的部分:
var fpacket: TMYPacket;
begin
fpacket := TVWTCPPacket.create;
//assign value to class properties
memo1.Lines.Text := TJson.ObjectToJsonString(fpacket); //throws error
在JSON转换过程中遇到错误。有人知道 Delphi Berlin 10.1 出了什么问题吗?我记得XE2存在一些RTTI问题,但不确定上述情况是否与Delphi旧缺陷有关。