本文整理自网络,侵删。
procedure TFmMain.BtnIPQueryClick(Sender: TObject);
var
S: string;
JSONStr: string;
country, area, region, city: string;
begin
//EditIP 是输入的要查询的 IP 地址
S := 'http://ip.taobao.com/service/getIpInfo.php?ip=';
JSONStr := IdHTTP1.Get(S + EditIP.Text);
if JSONStr = '' then Exit;
ParseIPAddressFromTaoBaoJSON(JSONStr, country, area, region, city);
Memo1.Lines.Add(country + '; ' + area + '; ' + region + '; ' + City);
end;
---------------------
这个函数使用了 TJSONValue 需要 uses System.JSON;
代码如下:
function TFmMain.ParseIPAddressFromTaoBaoJSON(const JSONStr: string; var country,
area, region, city: string): Boolean;
var
Obj: TJSONValue;
AValue: TJSONValue;
begin
Obj := TJSONObject.ParseJSONValue(JSONStr);
if Obj is TJSONObject then
begin
AValue := TJSONObject(Obj).Values['data'];
end;
if AValue is TJSONObject then
begin
country := TJSONObject(AValue).Values['country'].ToString;
area := TJSONObject(AValue).Values['area'].ToString;
region := TJSONObject(AValue).Values['region'].ToString;
city := TJSONObject(AValue).Values['city'].ToString;
end;
end;
---------------------
作者:pcplayer
来源:CSDN
原文:https://blog.csdn.net/pcplayer/article/details/80793709
相关阅读 >>
Delphi 能否把.txt文件的数据导入到access数据库中
Delphi xe5的新功能“ tlistview内置搜索过滤”
Delphi clipboard 截图后将图片数据复制到剪贴板
Delphi datamodule1 fdconnection1数据库连接
Delphi的datetostr strtodate格式灵活用法
更多相关阅读请进入《Delphi》频道 >>