Closed baxing closed 6 months ago
Hi,
I need to improve McJSON to meet this demand. Thanks for getting in touch, I'll work on it.
Hi, just committed a new version in order to manage nonexistent paths. Could you try it and report here?
Hi,
I'am not sure that should which method to check the existence of the path. So I test by
if N.Path('o.k2') = nil then
// do something
ShowMessage('nil')
else
// do something else ;
ShowMessage('ok');
but It still show error message that : Object reference is nil: has key "k2" It seems that Method : HasKey that is called within Method : Path is displaying this error.
or Did I do something wrong? Please advise.
Thank you
Hi,
Today's commit has a new Test20
that tests this and it is working here with Lazarus/FPC. Could you check with Delphi? I'm not in my office today:
N.AsJSON := '{"o": {"k1":"v1", "k2":"v2"}}';
// get second object using path of keys.
// ...
M := N.Path('o.k3');
Result := Result and (M = nil);
Thank you for your quick reply. But if it's convenient for you or it's during your working hours, please help answer my questions here.
N := TMcJsonItem.Create();
N.AsJSON := '{"o": {"k1":"v1", "k2":"v2"}}';
M := N.Path('o.k3'); //-- One
// M := N.Path('p'); //-- Two
// M := N.Path('ppp'); //-- Three
// M := N.Path('ppp.k3'); //-- Four
if M = nil then
// do something
ShowMessage('nil')
else
// do something else ;
ShowMessage('ok');
Result for above statement :
I think case "Two" and "Four" incorrect
Thank
Hi, You're right. I'll work on it.
Please, test last commit and report here.
@hydrobyte Thank very much, For now I think it's great to be able to check the existence of a path via method Path. 👍
And if you have another method that gives the same result, please recommend me.
@baxing, thanks for testing and reporting here.
I think Path()
returning nil
is good enough to test invalid object paths.
How to check nill of specific paht which throw to show error? such I want to check N.Path('o.k2') or N['o']['k2'] = nil ?
but now if path not exist McJSON show error automatically, but I don't want that.
I just want to be able to check for myself whether it's there or not. Even if there is, I will proceed with one thing. But if you don't have it, don't do another thing, for example.
or
Note : for JsonDataObjects can do this
Please guide me for this Thank you