Dexed, revived!

Basile B. b2.temp at gmx.com
Thu Feb 27 08:41:00 UTC 2020


On Wednesday, 26 February 2020 at 03:10:30 UTC, Akira1364 wrote:
> On Tuesday, 25 February 2020 at 21:45:04 UTC, Basile B. wrote:
>> Yeah but did you try to load a goddamn JSON recipe that 
>> **has** the BOM written ?
>> This stuff was there for a good reason you know ;)
>
> The reason BOMs weren't working for you was because you were 
> using a TMemoryStream to actually load the JSON files, and 
> TMemoryStream is just a stream of raw bytes that knows 
> absolutely nothing about encodings.
>
> All I had to do to get rid of your 30 lines of "BOM skipping" 
> code was change the file loading part to this:
>
> ```
> List := TStringList.Create;
> List.LoadFromFile(FFileName, TEncoding.UTF8);
> Stream := TStringStream.Create(List.Text, TEncoding.UTF8, 
> False);
> List.Free;
> Stream.Position := 0;
> ```
>
> And then continue by creating the TJSONParser from `Stream`. 
> Doing it that way works correctly BOM or no BOM.

Okay, I recognize that I've been a bit unfair in the previous 
message but remember that this constructor overload does not 
exist yet in the freepascal library version 3.0.4, so I could not 
use it, hence those 30 lines had to be written.


More information about the Digitalmars-d-ide mailing list