简体   繁体   English

使用JSON在Lazarus上进行Unicode强调

[英]Unicode accentuation on Lazarus with JSON

I'm having a problem with accentuation on Lazarus, when I get some JSON some characters appears as "\í" instead "í" for example. 我对Lazarus的重音有问题,例如当我得到一些JSON时,某些字符会显示为“ \\ u00ed”而不是“í”。 Someone has a solution? 有人有解决方案吗?

The code is this one 代码是这个

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; 

I found the solution, I made a class that convert unicode to UTF8 我找到了解决方案,我做了一个将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;  

and the previous code 和之前的代码

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;  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM