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('forecasts');
for Forecast in Forecasts do
begin
for Key in KEYS do
begin
Memo1.Lines.Add(Format('%s=%s',
[Key, Forecast.GetValue(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;