Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread JSON Parser issue
Tue, Dec 3 2013 7:44 AMPermanent Link

Matthew Jones

The data below my name is a JSON string that fails the parser. The internet tells
me that it is valid (jsonlint.com) but the TParser is being naive in its unescaping.

I shall have a look at it, but it looks to me like TParser.ParseString needs to be
more of a state-machine to handle this properly. Currently it checks to see if the "
is preceded by a \, and if so, that the \ isn't preceded with a \. But it doesn't
check that that \ isn't preceded with a \ and thus fails.

This might be argued to be a bit exceptional, but storing JSON in a JSON string
value is something I need to do.

I'll play with the code, and see if I can make it work.

/Matthew Jones/

(There are no line breaks in the original)

15:26:42 (Friday
B-C41B-4F1F-9125-BE340932D713\",\"name\":\"Gather 15:28:04 (Friday
,"usercount":10,"p_title":"GREEN = encourage RED =
","p_blob1enable":"true","p_list":"\\\"list\\\":[\\\"Provide more sales\\\",
\\\"Sales increase of widgets\\\", \\\"Combat widgets\\\", \\\"More
Tue, Dec 3 2013 7:57 AMPermanent Link

Matthew Jones

The code below seems to work. I'm happy for it to be used as Tim sees fit.

/Matthew Jones/

procedure TParser.ParseString;
   bEscapeActive : Boolean;
   bEscapeActive := false;
   while (FPos <= FTextLength) do
      if bEscapeActive then
         bEscapeActive := false;
         if (FText[FPos]='"') then
//            if (FText[FPos-1] <> '\') or
//            ((FPos > 2) and (FText[FPos-2]='\')) then
//            begin
   //         end
   //         else
   //         Inc(FPos);
         else if (FText[FPos]='\') then
            bEscapeActive := true;
   if (FEnd=0) then
      raise EError.Create(Translate('ERR_PARSE_TERMSTR',[IntToStr(FStart-1)]));
Mon, Dec 9 2013 6:32 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.


Email timyoung@elevatesoft.com


<< The code below seems to work. I'm happy for it to be used as Tim sees
fit. >>

Thanks, I'll make sure that it's tested thoroughly and include it in 1.03.

Tim Young
Elevate Software