You are not logged in.
Pages: 1
Hi,
I'm writing routine to compare two json objects (DocVariant). All elements in original must be in other json, but other json can contain some extra elements and order can vary. For that I need to detect type of individual elements
a := _json('{"arr":[1,2,3],"integer":2,"isnull":null,"str":"somestring","float":3.14,"subobject":{"a":"b","c":1}}');
for I := 0 to a._count-1 do
begin
s := a.name(i);
Writeln('Object name: ',s,' -------------');
b := a._(i);
if varisnull( b) then
Writeln('is null')
else
begin
Writeln( 'Docvariantdata: ',Tdocvariantdata ( b).VarType );
Writeln( 'kind: ',ord(Tdocvariantdata ( b).Kind) );
end;
end;
Will print
Object name: arr -------------
Docvariantdata: 16396
kind: 0
Object name: integer -------------
Docvariantdata: 3
kind: 0
Object name: isnull -------------
is null
Object name: str -------------
Docvariantdata: 16396
kind: 0
Object name: float -------------
Docvariantdata: 6
kind: 0
Object name: subobject -------------
Docvariantdata: 16396
kind: 0
so array, string and object are exactly same! What i'm missing?
Of course I could convert b to string and check if it starts with [ or { but that somehow seems stupid
thanks
mika
Last edited by MikaK (2019-05-10 05:37:31)
Offline
Instead of Tdocvariantdata ( b).Kind try _Safe(b).Kind. Or better yet, make a/b of PDocVariantData or TDocVariantData
Offline
Thanks, with _safe(b) it worked.
Offline
Pages: 1