You are not logged in.
Pages: 1
I have a Tdocvariant that has the structure:
{
"var1":[
{
"v1":[
{
"a":"1",
"b":"2"
}
],
"v2":"something"
}
],
"var2":"aaa"
}
How can I assigned the var1 part of the above Tdocvariant to a pascal array of the following record type:
type
Dv1=record
a,b:rawutf8;
end;
Dvar1=record
v1:array of Dv1;
v2:rawutf8;
end;
var var1:array of Dvar1;
Last edited by dcoun (2023-03-30 18:39:51)
Offline
DynArrayLoadJson can do the job but it is a double conversion or am I missing something?
Offline
I have a Tdocvariant in a variant variable and I want to assign a part of it ("var1") to an other pascal variable (var1) which is a record with the same structure.
If I have understood ok, tdocvariant is a utf8string in reality, and not a real record inside it. Is it like that?
Offline
I have a Tdocvariant in a variant variable and I want to assign a part of it ("var1") to an other pascal variable (var1) which is a record with the same structure.
Do you mean this?
type
TArrItem = packed record
a, b: RawUtf8;
end;
TDataItem = packed record
v1: array of TArrItem;
v2: RawUtf8;
end;
TDataItemList = array of TDataItem;
const
JSON_DATA: RawJson = '{"var1":[{"v1":[{"a":"1","b":"2"},{"a":"3","b":"4"}],"v2":"something"}]}';
var
doc: TDocVariantData;
list: TDataItemList;
begin
doc.InitJson(JSON_DATA, mFastFloat);
if DynArrayLoadJson(list, Pointer(doc.A['var1'].ToJson), TypeInfo(TDataItemList)) <> Nil then
ShowMessage(Utf8ToString(FormatUtf8('% - %', [list[0].v1[0].a, list[0].v2])));
Arnaud does it in a similar way in a few places.
With best regards
Thomas
Offline
That answers my question. Thanks a lot tbo.
Last edited by dcoun (2023-03-31 18:53:53)
Offline
Pages: 1