You are not logged in.
Pages: 1
I'm serialize record to json using RecordSaveJSON, and I need to ignore a field.
Ex:
TMyRecord = record
id: string;
name: string;
last_name: string;
end;
I need to ignore the id field when converting to json -> { "name":"john", "last_name":"wick"}
Offline
maybe it is not the best way, but if I need to edit json (in a quick-coded way), I usually use TDocVariant. Smth like this:
var
LRecord: TMyRecord;
LDocVar: TDocVariantData;
begin
LRecord.id := '1';
LRecord.name := '22';
LRecord.last_name := '333';
LDocVar.InitFromTypeInfo(LRecord, TypeInfo(TMyRecord), False, []);
LDocVar.Delete('id');
Memo1.Text := UTF8ToString(LDocVar.ToJSON);
...
{"name":"22","last_name":"333"}
btw, the record is better to be packed, I guess:
In practice, the record types should be defined as packed record, so that low-level access will be easier to manage by the serializers.
Offline
IMHO the Customized serialization would be a better approach.
Offline
Pages: 1