onryldz / x-superobject

Delphi Cross Platform Rapid JSON
316 stars 118 forks source link

Cannot create an TSuperObject with string field containing a linefeed/linebreak #91

Closed stephanewierzbicki closed 8 years ago

stephanewierzbicki commented 8 years ago

Hello, I'm getting an exception when using line linefeed/linebreak in my JSON string : TSuperObject.Create('{"adress"="My Adress'+#13#10+'My City"}');

Is it possible to dynamically replace such special char with escape sequences ?

legitimate escape sequences within a JSON string: \" \ \/ \b \f \n \r \t \u followed by four-hex-digits

stephanewierzbicki commented 8 years ago

Hello Onur,

Thank you for your commit. I've tested my code (using CreateWithEscape) and I'm getting this exception :

Exception 'first chance' à $7517DAD8. exception class TJSONSyntaxError with message 'Unexpected token ILLEGAL. (Line: 0 Col: 9)'. Process CRM.exe (416)

onryldz commented 8 years ago

Hi Stephane, You have to use '=' instead of ':' for json field operator.

As a sample: TSuperObject.CreateWithEscape('{"adress":"My Adress'+#13#10+'My City"}');

stephanewierzbicki commented 8 years ago

I'm a noob... I did a typo.

I've tested CreateWithEscape but it still fails. I've have uploaded a JSON sample. You can reproduce it easily :

Procedure Load;
var X: ISuperObject;
    SL:TStringlist;
begin
   sl := TStringlist.create;
     try
      sl.LoadFromFile('D:\Formated.txt')  ;
      X:= TSuperObject.CreateWithEscape(sl.Text);
     finally
       sl.free;
     end;
end;

Formated.txt