#1 2024-04-24 07:52:39

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

TDocVariantData.GetValueByPath and Arrays

GetValueByPath can easily handle a path such as 'Item.0,Name', where the second part is an array index.

However, when starting of an array with, 0.Name would work, if it were not for the check

  if (cardinal(VType) <> DocVariantVType) or
     (not IsObject) then

Changing that to

  if (cardinal(VType) <> DocVariantVType) or
     (not (IsObject or IsArray)) then

it works perfectly.

Regards,
Daniel

Last edited by sakura (2024-04-24 07:53:08)

Offline

#2 2024-04-24 12:32:59

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: TDocVariantData.GetValueByPath and Arrays

Offline

#3 2024-04-26 06:37:06

sakura
Member
From: Germany
Registered: 2018-02-21
Posts: 239
Website

Re: TDocVariantData.GetValueByPath and Arrays

Thanks, works!

Offline

#4 2024-04-28 10:26:58

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: TDocVariantData.GetValueByPath and Arrays

Now IDocDict doesn't work correctly, use "exists" to check for existing keys and always return false

Offline

#5 2024-04-28 15:24:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,662
Website

Re: TDocVariantData.GetValueByPath and Arrays

@lfyey121
Please refine your statement, with a https://stackoverflow.com/help/minimal- … le-example

Exists() is tested and works.
https://github.com/synopse/mORMot2/blob … .pas#L4134

If you want to use paths, you need to enable it setting the PathDelim property to the delimiter char, typically '.' or '/';

Offline

#6 2024-04-29 01:31:51

lfyey121
Member
From: china
Registered: 2022-08-25
Posts: 66

Re: TDocVariantData.GetValueByPath and Arrays

Sorry, my mistake, my json file format is corrupted.

Offline

Board footer

Powered by FluxBB