问题描述
我有一个对象与一些TObjectList<> - 字段,我尝试编码为JSON的帮助形式。
I have a object with some TObjectList<>-fields that I try to encode as JSON with help form SuperObject.
TLogs = TObjectList<TLog>;
TMyObject = class(TObject)
private
FLogs: TLogs;
end;
深入SuperObjects代码,有一个ToClass过程,迭代字段并将其添加到json结果
Deep inside SuperObjects code, there is a ToClass procedure, iterating the fields and add them to the json result.
在这个循环中,有一个检查TRttiFields FieldType。如果没有,它会跳过对象。
In this loop, there is a check on the TRttiFields FieldType. If it's nil, it skips the object.
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为零。为什么?
My generic list fields have a FieldType of nil. Why?
如何使SuperObject序列化我的对象列表?
How can I make SuperObject serialize my list of objects?
推荐答案
这是Delphi的RTTI创建中的一个已知问题。如果你这样宣告你的泛型类,那就不行了。您需要使用类关键字。
This is a known issue in Delphi's RTTI creation. If you declare your generic class like that, it won't work. You need to use the class keyword.
TLogs = class(TObjectList<TLog>);
希望这将在下一个版本中修复。
Hopefully this will be fixed in the next release.
这篇关于Delphi Superobject,通用列表到json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!