El 02/06/15 a las 04:20, Michael Van Canneyt escibió:


On Mon, 1 Jun 2015, "Leonardo M. Ramé" wrote:

El 30/05/15 a las 13:29, silvioprog escibió:
On Sat, May 30, 2015 at 12:14 PM, "Leonardo M. Ramé" <l.r...@griensu.com
<mailto:l.r...@griensu.com>> wrote:


[Window Title]
project1

[Content]
{ "var1" : "bGVvbmFyZG8=" } - leonardo

[OK]

But after take a look at your code, it seems better to use as:

myString := '{ "var1": "' + StringToJsonString(Base64EncodedString) +
'" }'

Because function "StringToJsonString" will encode string in a
JSON-escape string.


Hi Silvio, can you try encoding the attached file, then output using
both methods?.

I tested your file with the following program:

program jsonb;

uses sysutils, classes, fpjson, jsonparser, base64;

Var
   O : TJSONObject;
   F : TFileStream;
   S : TStringStream;

begin
   S:=Nil;
   O:=Nil;
   try
     F:=TFileStream.Create(ParamStr(1),fmOpenRead);
     S:=TStringStream.Create('');
     With TBase64EncodingStream.Create(S) do
       try
         CopyFrom(F,0);
         Flush;
         O:=TJSONObject.Create(['file',S.DataString]);
       finally
         Free;
       end;
     FreeAndNil(S);
     S:=TStringStream.Create(O.Get('file'));
     S.Position:=0;
     FreeAndNil(F);
     F:=TFileStream.Create(ChangeFileExt(paramstr(1),'.base64'),fmCreate);
     F.CopyFrom(S,0);
   finally
     O.Free;
     F.Free;
     S.Free;
   end;
end.

cadwal: >./jsonb plantilla-original.ott
cadwal: >base64 -d plantilla-original.base64 > b.ott
cadwal: >ls *.ott -l
-rw-rw-r-- 1 michael michael 41956 Jun  2 09:16 b.ott
-rw-rw-r-- 1 michael michael 41956 Jun  2 09:05 plantilla-original.ott
cadwal: >cmp b.ott plantilla-original.ott

cmp reports all is well.

Michael.



Thanks Michael, what if you save the json object to file using:

with TStringList.Create do
begin
  Text := O.AsJson;
  SaveToFile('test.json');
end;

Then copy the content of the "file" variable, and save as test.base64? and try base64 -d test.base64, this is what I tried to do and got errors decoding.

--
_______________________________________________
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to