本文整理自网络,侵删。
procedure TForm1.Button1Click(Sender: TObject);begin RESTRequest1.ResetToDefaults; RESTClient1.ResetToDefaults; RESTResponse1.ResetToDefaults;
RESTClient1.BaseURL := 'http://weather.livedoor.com/'; RESTRequest1.Resource := 'forecast/webservice/json/v1?city={CITY}'; RESTRequest1.Params.AddItem('CITY', Edit1.Text, TRESTRequestParameterKind.pkURLSEGMENT); RESTRequest1.Execute;end;
procedure TForm1.RESTRequest1AfterExecute(Sender: TCustomRESTRequest);const KEYS: array [0 .. 2] of string = ('dateLabel', 'telop', 'date');var JSONValue: TJSONValue; Forecasts: TJSONArray; Forecast: TJSONValue; Key: string;begin Memo1.Lines.Clear;; Label1.Text := 'URI: ' + Sender.GetFullRequestURL + ' Execution time: ' + IntToStr(Sender.ExecutionPerformance.TotalExecutionTime) + 'ms'; if Assigned(RESTResponse1.JSONValue) then begin JSONValue := RESTResponse1.JSONValue; Forecasts := JSONValue.GetValue<TJSONArray>('forecasts'); for Forecast in Forecasts do begin for Key in KEYS do begin Memo1.Lines.Add(Format('%s=%s', [Key, Forecast.GetValue<TJSONString>(Key).ToString])); end; end; end;end;
procedure TForm1.RESTRequest1HTTPProtocolError(Sender: TCustomRESTRequest);begin Memo1.Lines.Add(Sender.Response.StatusText); Memo1.Lines.Add(Sender.Response.Content);end;
相关阅读 >>
Delphi datamodule1 fdconnection1数据库连接
Delphi tfdquery提交tfdmemtable修改的数据
Delphi fmx 从app程序直接跳转到支付宝付款转帐页面
更多相关阅读请进入《Delphi》频道 >>