You are not logged in.
Hi
According to docs GetValueByPath will return Unassigned if the path does not match with the docvar content, so it seems an easy way to read optional nodes
But this code raises "Exception class EDocVariant with message '[Imps] property not found'. "
v := _Obj([ 'Config', _Obj([]) ]);
m := _Safe(v).GetValueByPath('Config.Imps');
if VarIsEmptyOrNull(m) then
ShowMessage('error');
I try this code too:
v := _Obj([ 'Config', _Obj([]) ]);
if not _Safe(v).GetValueByPath('Config.Imps', m) then
ShowMessage('error');
I can use [dvoReturnNullForUnknownProperty] option but I prefer not, and be more strict and use late binding for required properties (expecting exceptions if not exist) and try read/validate optional nodes with GetValueByPath
Is it the correct behavior ?
thanks
Offline
hi ab,
Using the same topic about tdocvariant.
From certain decimal places on a double value json is no longer recognized as valid.
Is this expected behavior?
NOTE: I know about the loss of precision, and that I can use the dvoAllowDoubleValue option. Just checking if it's expected.
v := _JSON('{"value":0.001}'); //ok
v := _JSON('{"value":0.00001}'); //not recognized as valid json
Offline
You are right.
GetValueByPath() should not raise an exception but return false.
I have just updated TDocVariant.Lookup() to reflect this behavior.
Thanks for your quick respond, I see the fix in mormot2
but not in 1.18 , Im using that version, sorry I did not mention it
Offline