Lazarus 的 Unicode 重音 JSON
Unicode accentuation on Lazarus with JSON
我在 Lazarus 上遇到重音问题,当我得到一些 JSON 时,一些字符显示为“\u00ed”而不是“í”。有人有解决办法吗?
密码就是这个
procedure TForm1.Button1Click(Sender: TObject);
Var
S : String;
begin
S := '';
With TFPHttpClient.Create(Nil) do
try
S:=Get(Edit1.Text);
finally
Free;
end;
Memo1.Lines.Text:=Trim(S);
end;
我找到了解决方案,我制作了一个 class 将 unicode 转换为 UTF8
function TForm1.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(StrToInt('$' + HexCode));
Result := AnsiReplaceStr(Result, '\u' + HexCode,
UTF8Encode(DecodedChars));
FoundPos := Pos('\u', Result);
end;
end;
和前面的代码
procedure TForm1.Button1Click(Sender: TObject);
var
s: String;
begin
s := '';
With TFPHttpClient.Create(Nil) do
try
s :=Get(Edit1.Text);
s := DecodeUnicodeEscapes(s);
finally
Free;
end;
Memo1.Lines.Text:=Trim(s);
end;
我在 Lazarus 上遇到重音问题,当我得到一些 JSON 时,一些字符显示为“\u00ed”而不是“í”。有人有解决办法吗?
密码就是这个
procedure TForm1.Button1Click(Sender: TObject);
Var
S : String;
begin
S := '';
With TFPHttpClient.Create(Nil) do
try
S:=Get(Edit1.Text);
finally
Free;
end;
Memo1.Lines.Text:=Trim(S);
end;
我找到了解决方案,我制作了一个 class 将 unicode 转换为 UTF8
function TForm1.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(StrToInt('$' + HexCode));
Result := AnsiReplaceStr(Result, '\u' + HexCode,
UTF8Encode(DecodedChars));
FoundPos := Pos('\u', Result);
end;
end;
和前面的代码
procedure TForm1.Button1Click(Sender: TObject);
var
s: String;
begin
s := '';
With TFPHttpClient.Create(Nil) do
try
s :=Get(Edit1.Text);
s := DecodeUnicodeEscapes(s);
finally
Free;
end;
Memo1.Lines.Text:=Trim(s);
end;