本文整理自网络,侵删。
function GetTranslatedText(const OriText: string): string;var Json: TQJson;const WebRestApiUrl = 'http://fanyi.youdao.com/translate?&doctype=json&type=AUTO&i=%s';begin Json := TQJson.Create; try try Json.Parse(CSimpleGet(Format(WebRestApiUrl, [TURLEncoding.URL.Encode(OriText)]))); //CSimpleGet 这里可以搜索本站用 idhttp nethttpclient 实现获取 Result := Json.ItemByPath('\translateResult[0][0]\tgt').AsString; except on e: Exception do Result := ''; end; finally FreeAndNil(Json); end;end;
感谢 黑夜杀手 提供
相关阅读 >>
Delphi 自带rest调试工具 restdebugger 用法
pchar和array [0..255] of char的区别
Delphi idhttp 设置cookie 和访问后读取cookie 值
Delphi 在firemonkey应用程序中使用torientationsensor获取设备倾斜和指南针航向
更多相关阅读请进入《Delphi》频道 >>