Delphi IdHTTP Http.Get 获取json数据


本文整理自网络,侵删。

 
unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

uses
  IdBaseComponent,
  IdComponent,
  IdTCPConnection,
  IdTCPClient,
  IdHTTP,
  Math;



function Parse(text, sol, sag: string): String;    /// Function Author: Ali Zairov
begin
  Delete(text, 1, Pos(sol, text) + Length(sol) - 1);
  Result := Copy(text, 1, Pos(sag, text) - 1);
end;


Function WTemperature(APIID: String; City: String): String;
var
  XML: TStringList;
  Http: TIdHTTP;
begin
  XML := TStringList.Create;
  Http := TIdHTTP.Create(Nil);
  XML.Text := Http.Get('http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel=手机号');
 Result := Parse(XML.Text, 'location":', '}},');//Copy(Parse(XML.Text, 'location":', '}},'), 0, 10);
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text:=WTemperature('','');
end;

end.

相关阅读 >>

Delphi实现阿里云印刷文字识别_身份证识别

Delphi 输入法设置(imemode与imename)

Delphi 使用shellexecuteex运行应用程序并等待完成

Delphi 获取随机字符串的方法 getrandomstring

Delphi下遍历文件夹下所有文件的递归算法

Delphi xe 的 tdictionary

Delphi richedit memo1支持中文搜索、向上查找、区分大小写

Delphi 获取url特殊路径

Delphi中判断某个文件是否已经打开

Delphi 操作webbrowser 元素值

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...