[Lazarus] JSon stream to unicode?
Michael Fuchs
freepascal at ypa-software.de
Sat Nov 13 00:43:40 CET 2010
Leonardo M. Ramé schrieb:
> Hi, I'm receiving from a Delphi 7 app a unicode Stream (from Synapse
> library) containing Unicode data and I need to show it in a Lazarus
> form. How can I convert it to look correctly on screen?.
>
> Example:
>
> The string "Leonardo Ramé" is shown as "Leonardo Ram\u009".
>
I had the same problem and use now the following function for decoding:
function DecodeUnicodeEscapes(EscapedString: String): String;
var
FoundPos: LongInt;
HexCode: String;
DecodedChars: String;
begin
Result := EscapedString;
FoundPos := Pos('\u', Result);
while (FoundPos <> 0) and (FoundPos < Length(Result) - 4) do begin
HexCode := Copy(Result, FoundPos + 2, 4);
DecodedChars := WideChar(Hex2Dec(HexCode));
Result := AnsiReplaceStr(Result, '\u' + HexCode,
UTF8Encode(DecodedChars));
FoundPos := Pos('\u', Result);
end;
end;
hth
Michael
More information about the Lazarus
mailing list