[fpc-pascal] TJSONData.FindPath() troubles where data contains dots.

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Wed Feb 8 17:08:16 CET 2017


Hi,

I've studied the following documenation to make sure I'm using
FindPath() correctly.


http://www.freepascal.org/docs-html/3.0.0/fcl/fpjson/tjsondata.findpath.html

Now, I have the following JSON data.... I omitted what is not relevant.
========================
{
   ...snip...
	"VersionDependencies": {
		"2.5.0": {
			"packages": "master",
			"framework": "3.11.0"
		}
	}
}
========================

I can do Data.FindPath("VersionDependencies") and it finds the data node
without problems.

But when I try:

var
  ver: string:
begin
  ver := '2.5.0';
  ...snip...
  Data.FindPath('VersionDependencies.'+ver)

It never finds the "2.5.0" data node. I'm assuming the dots in the
version string is what is causing the problem in fcl-json. Initially I
thought I could add extra quotes around the version string. Like so:

  Data.FindPath('VersionDependencies.'''+ver+'''')

But that didn't work either.

Is this a bug of some sorts, or is there another way around this problem?

I guess my only option is to use TJSONenum and iterate of the
"VersionDependencies" data, and manually look for the data node I'm
interested in. Like so:

  d := Data.FindPath('VersionDependencies');

  for ItrItem in d do
    if d.Key = ver then
       ...snip...


Is there another way of finding the data I'm interested in?

Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp



More information about the fpc-pascal mailing list