Recent

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

lainz

  • Hero Member
  • *****
  • Posts: 3829
[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: 256
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

Windows 10 (64 bit)
Lazarus: 2.0.12 / Trunk x32

lainz

  • Hero Member
  • *****
  • Posts: 3829
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

jamie

  • Hero Member
  • *****
  • Posts: 4751
Re: JSONTools error while parsing
« Reply #3 on: June 02, 2021, 05:13:00 pm »
I am currently staring at the Json Tools file...

From the reported errors I would try this off the side..

Load the file in question into a string and then use the StringReplace in the same way its being used in the Parse function then examine the resulting string in a memo or something.

I see that StringReplace is trying to replace all the '\"\"' with '\"'

Because if that corrupts the return string then the rest of it is not going to work..
The only true wisdom is knowing you know nothing

engkin

  • Hero Member
  • *****
  • Posts: 2872
Re: JSONTools error while parsing
« Reply #4 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: 3829
Re: JSONTools error while parsing
« Reply #5 on: June 02, 2021, 06:10:58 pm »
Many thanks engkin  :)

sysrpl

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

 

TinyPortal © 2005-2018