【发布时间】:2018-02-17 23:49:32
【问题描述】:
我正在尝试使用 mORMot 框架将 TObject 序列化为 JSON。不幸的是,结果始终为空。
我要序列化的类是:
type ApmTime = class(TObject)
private
function currentTime() : String;
published
property Current_time: String read currentTime;
public
constructor Create;
end;
constructor ApmTime.Create;
begin
inherited;
end;
function ApmTime.currentTime() : String;
begin
result := TimeToStr(Now);
end;
并且对应的mORMot方法在SynCommons中定义:
currentTime := ApmTime.Create;
Write(ObjectToJSON(currentTime, [woFullExpand]));
这总是返回空值。在单步执行TTextWriter.WriteObject(位于单元SynCommons)之后,以下代码似乎是将生成的json 设置为null:
if not(woFullExpand in Options) or
not(Value.InheritsFrom(TList)
{$ifndef LVCL} or Value.InheritsFrom(TCollection){$endif}) then
Value := nil;
if Value=nil then begin
AddShort('null');
exit;
我期待一些事情:
{
"Current_time" : "15:04"
}
【问题讨论】: