You are not logged in.
Pages: 1
Can we add new util function in SynCommons for "true JSON" (used for AJAX request) for converting TObjectList?
It will be very useful. ObjectToJSON is not the option (it return Table name in result)
Patch ofc included:
function ObjectListToJson(Value: TObjectList; ListOptions: TTextWriterWriteObjectOptions=[woDontStoreDefault]): RawUTF8;
var
i: integer;
begin
if (Value=nil) or (Value.Count = 0) then
result := '[]' else
with DefaultTextWriterJSONClass.CreateOwnedStream do
try
Add('[');
for i := 0 to Value.Count - 1 do
begin
WriteObject(Value[i], ListOptions);
Add(',');
end;
CancelLastComma;
Add(']');
SetText(result);
finally
Free;
end;
end;
best regards,
Maciej Izak
Last edited by hnb (2015-09-16 07:13:52)
best regards,
Maciej Izak
Offline
It is true for TObjectList but It doesn't work for TObjectList items.
best regards,
Maciej Izak
Offline
By default, TObjectList will set the woStoreClassName for its nested objects, unless the new woObjectListWontStoreClassName option is defined.
Online
Thanks! Your patch is much better
best regards,
Maciej Izak
Offline
Pages: 1