首页 文章

Delphi Superobject,json的通用列表

提问于
浏览
4

我有一个带有一些TObjectList <>的对象 - 我尝试使用帮助形式SuperObject编码为JSON的字段 .

TLogs = TObjectList<TLog>;
TMyObject = class(TObject)
private
  FLogs: TLogs;
end;

在SuperObjects代码内部,有一个ToClass过程,迭代字段并将它们添加到json结果中 .

在此循环中,检查TRttiFields FieldType . 如果它为零,则跳过该对象 .

for f in Context.GetType(Value.AsObject.ClassType).GetFields do
  if f.FieldType <> nil then
  begin
    v := f.GetValue(value.AsObject);
    result.AsObject[GetFieldName(f)] := ToJson(v, index);
  end

我的通用列表字段的FieldType为nil . 为什么?

如何让SuperObject序列化我的对象列表?

1 回答

  • 7

    这是Delphi 's RTTI creation. If you declare your generic class like that, it won'工作中的一个已知问题 . 您需要使用 class 关键字 .

    TLogs = class(TObjectList<TLog>);
    

    希望这将在下一个版本中修复 .

相关问题