Recent

Author Topic: [Solved] JSONTools error while parsing  (Read 3766 times)

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
[Solved] JSONTools error while parsing
« on: June 02, 2021, 04:36:54 pm »
This is the json file
https://www.dropbox.com/s/4i8o9gpsjdr1pd2/file.json?dl=0

This is our copy of jsontools.pas
https://www.dropbox.com/s/ux1ai5q2zublt1p/jsontools.pas?dl=0

Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. var
  3.   j: TJSONNode;
  4. begin
  5.   j := TJSONNode.Create;
  6.   j.LoadFromFile('file.json');
  7.   j.Free;
  8. end;

Its a valid JSON and it says it can't parse.

I'm not an expert on parsing, only I know very basic stuff about it.

Any ideas?
« Last Edit: June 02, 2021, 06:11:09 pm by lainz »

sstvmaster

  • Sr. Member
  • ****
  • Posts: 299
Re: JSONTools error while parsing
« Reply #1 on: June 02, 2021, 04:51:51 pm »
I have no idea, but look at the link: https://wiki.freepascal.org/fcl-json#From_JsonViewer

And in the lazarus folder under tools there is an tool called: jsonviewer

greetings Maik

Windows 10,
- Lazarus 2.2.6 (stable) + fpc 3.2.2 (stable)
- Lazarus 2.2.7 (fixes) + fpc 3.3.1 (main/trunk)

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: JSONTools error while parsing
« Reply #2 on: June 02, 2021, 04:57:11 pm »
I have no idea, but look at the link: https://wiki.freepascal.org/fcl-json#From_JsonViewer

And in the lazarus folder under tools there is an tool called: jsonviewer

Yes but our entire project uses jsontools, not fpcjson

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: JSONTools error while parsing
« Reply #3 on: June 02, 2021, 05:55:44 pm »
It fails at the \\" as in:
Code: Pascal  [Select][+][-]
  1.   s:='[{"snombre":"PANTENE ENJ L.Y SEDOSO 400ML\\","rpreciou":285}]';

While this works:
Code: Pascal  [Select][+][-]
  1.   s:='[{"snombre":"PANTENE ENJ L.Y SEDOSO 400ML","rpreciou":285}]';

Tested using:
Code: Pascal  [Select][+][-]
  1.   j := TJSONNode.Create;
  2.   j.Parse(s);
  3.   j.Free;

Your file has one instance of \\, remove it and it'll work.

Changing NextToken:
Code: Pascal  [Select][+][-]
  1. function NextToken(var C: PChar; out T: TJsonToken): Boolean;
  2. .....
  3.   if C^ = '"'  then
  4.   begin
  5.     Inc(C);
  6.     repeat
  7.       if C^ = '\' then
  8.       begin
  9.         Inc(C);
  10.         if C^ = '\' then
  11.           Inc(C)
  12.         else if C^ = '"' then
  13.           Inc(C)
« Last Edit: June 02, 2021, 06:05:16 pm by engkin »

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: JSONTools error while parsing
« Reply #4 on: June 02, 2021, 06:10:58 pm »
Many thanks engkin  :)

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: [Solved] JSONTools error while parsing
« Reply #5 on: July 31, 2021, 02:48:26 pm »
This issue has been fixed in a updated release.

 

TinyPortal © 2005-2018