線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1396
推到 Plurk!
推到 Facebook!

post网页汉字显示为编码如何转为汉字?

缺席
shuiying
一般會員


發表:1
回覆:1
積分:0
註冊:2007-11-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2010-08-14 11:41:52 IP:222.221.xxx.xxx 訂閱

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComObj;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
http: Variant;
begin
http := CreateOleObject('MSXML2.XMLHTTP');
http.open('POST', 'http://127.0.0.1/gdzc/php/login.php', False);
http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http.send('username=李伟&password=8888');
Memo1.Text := http.responseText;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
http: Variant;
s: WideString;
begin
http := CreateOleObject('MSXML2.XMLHTTP');
http.open('POST', 'http://127.0.0.1/gdzc/php/asset_list.php', False);
http.send('start=1&limit=10');
s := UTF8Decode( http.responseText);
Memo1.Text := s;
end;

end.





注:网页是php编写,输出字符集为UTF-8,但在Delphi中POST下来后,汉字就只显示如图所示的编码而不是汉字,怎么转化为显示汉字呢?
附加檔案:4c66107ff3fca_1.jpg
編輯記錄
shuiying 重新編輯於 2010-08-14 11:42:44, 註解 無‧
shuiying
一般會員


發表:1
回覆:1
積分:0
註冊:2007-11-14

發送簡訊給我
#2 引用回覆 回覆 發表時間:2010-08-14 15:47:26 IP:116.52.xxx.xxx 訂閱
问题解决,采用了本论坛的代码。
unit Hanzi;
interface
uses
Classes,StrUtils,SysUtils;
function RTFUniCode(aTagText: AnsiString): WideChar;
function RTFUniToHanZi(aText: string): string;
function UniCodeRTF(aWC: WideChar): AnsiString;
implementation
function RTFUniCode(aTagText: AnsiString): WideChar;
var aAC: array[0..1] of Char;
begin
Result := #0;
if Length(aTagText) <> 6 then Exit;
if Copy(aTagText, 1, 2) <> '\u' then Exit;
HexToBin(PAnsiChar(Copy(aTagText, 5, 2)), @aAC[0], 1);
HexToBin(PAnsiChar(Copy(aTagText, 3, 2)), @aAC[1], 1);
Result := PWideChar(@aAC)^;
end;
function RTFUniToHanZi(aText: string): string;
var
i: Integer;
s1: string;
s2: string;
begin
i := Pos('\u', aText);
while (i > 0) do
begin
s1 := Copy(aText, i, 6);
s2 := RTFUniCode(s1);
aText := StringReplace(aText, s1, s2, [rfReplaceAll]);
i := Pos('\u', aText);
if i = 0 then Break;
end;
Result:=aText;
end;

function UniCodeRTF(aWC: WideChar): AnsiString;
var aAC: array[0..1] of AnsiChar;
begin
Result := '';
if aWC <> '' then begin
BinToHex(PAnsiChar(@aWC) 1, @aAC, 1);
Result := '\u' aAC;
BinToHex(PAnsiChar(@aWC), @aAC, 1);
Result := Result aAC;
end;
end;
end.
系統時間:2017-10-19 15:22:53
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!