[Lazarus] [fpc-pascal] Tests results of several pascal based JSON parsers
Anthony Walter
sysrpl at gmail.com
Sat Aug 31 09:13:31 CEST 2019
Michael, regarding this unicode problem, all the code has already been
posted in this thread.
program Test;
uses
FPJson, JsonParser, JsonTools;
const
UnicodeChars = '{ "name": "Joe®Schmoe", "occupation": "bank teller \u00Ae
" }';
function VerifyUnicodeCharsFPJson: Boolean;
var
N: TJSONData;
begin
N := GetJSON(UnicodeChars);
Result := (N.Items[0].AsUnicodeString = 'Joe®Schmoe') and
(N.Items[1].AsUnicodeString = 'bank teller ® ');
N.Free;
end;
function VerifyUnicodeCharsJsonTools: Boolean;
const
UnicodeChars = '{ "name": "Joe®Schmoe", "occupation": "bank teller \u00Ae
" }';
var
N: TJsonNode;
begin
N := TJsonNode.Create;
N.Parse(UnicodeChars);
Result := (N.Child(0).AsString = 'Joe®Schmoe') and (N.Child(1).AsString =
'bank teller ® ');
N.Free;
end;
begin
WriteLn('FPJson Handles unicode chars correctly: ',
VerifyUnicodeCharsFPJson);
WriteLn('JsonTools Handles unicode chars correctly: ',
VerifyUnicodeCharsJsonTools);
end.
Output:
FPJson Handles unicode chars correctly: FALSE
JsonTools Handles unicode chars correctly: TRUE
Tested on both Linux and Windows with the same results. Differing versions
of FPC on differing platforms and other people have verified the same
result. Try the tests yourself. Maybe you can figure out what's going wrong.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190831/5ab1e3f8/attachment.html>
More information about the lazarus
mailing list