打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
JSON 之 SuperObject(16): 实例

同上例类似, 通过 'http://clients1.google.cn/complete/search?&q=' + "关键字" 可以获取 Google 的关键字搜索排名.

我用 Delphi 为关键字得到的结果是:
window.google.ac.h(  ["Delphi",[      ["delphi 教程", "375,000 结果", "0"],      ["delphi盒子", "74,900 结果", "1"],      ["delphi 下载", "1,580,000 结果", "2"],      ["delphi7 下载", "1,600,000 结果", "3"],      ["delphi是什么", "497,000 结果", "4"],      ["delphi 字符串函数", "352,000 结果", "5"],      ["delphi7 序列号", "302,000 结果", "6"],      ["delphi2009下载", "20,600 结果", "7"],      ["delphi7", "1,330,000 结果","8"],      ["delphi2009正式版下载", "5,710 结果", "9"]    ]  ])

上面结果以 window.google.ac.h(...) 的形式给出, 下面的操作关键就是给 ISuperObject 一个名为 "window.google.ac.h" 的方法, 并指向自定义的过程, 并在过程中完成解析.

运行效果图:


代码文件:
unit Unit1;interfaceuses  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,  Dialogs, StdCtrls;type  TForm1 = class(TForm)    Memo1: TMemo;    Edit1: TEdit;    Button1: TButton;    procedure Button1Click(Sender: TObject);  end;var  Form1: TForm1;implementation{$R *.dfm}uses MsXML, SuperObject;function ToUTF8Encode(str: string): string;var  b: Byte;begin  for b in BytesOf(UTF8Encode(str)) do    Result := Format('%s%s%.2x', [Result, '%', b]);end;procedure Proc(const This, Params: ISuperObject; var Result: ISuperObject);var  jo: ISuperObject;begin  Form1.Memo1.Clear;  for jo in Params['1'] do with Form1.Memo1.Lines do    Form1.Memo1.Lines.Add(jo.format('%2%: %0% - %1%'));end;procedure TForm1.Button1Click(Sender: TObject);const  u = 'http://clients1.google.cn/complete/search?&q=';var  jo: ISuperObject;  req: IXMLHTTPRequest;  url: WideString;begin  jo := SO;  jo.M['window.google.ac.h'] := @Proc;  url := u + ToUTF8Encode(Edit1.Text);  req := CoXMLHTTP.Create;  req.open('Get', url, False, EmptyParam, EmptyParam);  req.send(EmptyParam);  jo[req.responseText];end;end.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
JSON 之 SuperObject(15): 实例
JSON 之 SuperObject(11): TSuperTableString、TSuperAvlEntry
Delphi 获取图片中 像素的颜色值
delphi制作透明窗体
Delphi的图形处理(一)
delphi多线程编程
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服