You are not logged in.
Pages: 1
I registered a custom reader and writer
code:
aSerializer.AddJSONEscape(['Key',V.Key,'RowData',v.RowData]);
but return array proptery string is null
{"Key":"Eric","RowData":null}
rowdata is variant type dynamic array
Offline
thanks !
Below is my code for your reference
json:
'[{"Key":"Eric","RowData":["Eric",15]}]'
class function TSpiderDataitem.FVClassReader(const aValue: TObject;
aFrom: PUTF8Char; var aValid: boolean;
aOptions: TJSONToObjectOptions): PUTF8Char;
var
V: TSpiderDataItem absolute aValue;
Doc :TDocVariantData;
Values:array[0..10] of TValuePUTF8Char;
begin
result := JSonDeCode(aFrom, ['Key','RowData'], @Values[0],true);
aValid := (result <> nil);
if aValid then
begin
v.Key :=VAlues[0].ToString;
Doc.InitJSON(Values[1].Value);
V.FRowData :=Doc.Values;
(V.Collection as TSpiderDataCollection).parent.AddHash(
v.Key,V
);
end;
end;
class procedure TSpiderDataItem.FVClassWriter(const aSerializer:
TJSONSerializer; aValue: TObject; aOptions: TTextWriterWriteObjectOptions);
var
V: TSpiderDataItem absolute aValue;
Row:TDocVariantData;
begin
Row.InitArrayFromVariants(v.RowData);
aSerializer.AddJSONEscape(['Key',v.Key,'RowData',Variant(Row)]);
end;
Last edited by wangchong (2019-02-27 12:02:02)
Offline
Pages: 1