You are not logged in.
types:
type
TFieldData = record
FieldName : UTF8String;
FieldType : TFieldType;
FieldValue : Variant;
end;
TFieldDataArray = TArray<TFieldData>;
code:
var
s: RawUTF8;
Tab : TFieldDataArray;
DynArray : TDynArray;
OtherDynArray: TDynArray;
begin
//prepare array
SetLength(Tab, 2);
//prepare records
Tab[0].FieldName := 'name';
Tab[0].FieldType := ftString;
Tab[0].FieldValue := 'igor';
Tab[1].FieldName := 'count';
Tab[1].FieldType := ftInteger;
Tab[1].FieldValue := 15;
// prepare DynArray
DynArray.Init(TypeInfo(TArray<TFieldData>), Tab);
// serialize array of records to JSON
s := DynArray.SaveToJSON(False); // s = [{"FieldName":"name","FieldType":1,"FieldValue":"igor"},{"FieldName":"count","FieldType":3,"FieldValue":15}]
//trying to deserialize and AV
OtherDynArray.LoadFromJSON(pointer(s)); <======== exception
I get exception:
Access violation at address 00697DF3 in module 'demo.exe''. Write of address 75174F70
How do properly deserialize JSON to array od records?
Offline
Hi,
did you try to initialize OtherDynarray ?
Like OtherDynarray.Init(TypeInfo(TArray<TFieldData>), Tab)
Offline
Ehhh, I forgot that TDynArray is just a wrapper! Thx!
Offline