Delphiメーリングリストに投稿された東京電力電力供給状況APIを使ったプログラムをベースにして修正したプログラムです。
元のプログラムではJSONの解析にJSON – SuperObjectが使用されています。
今回のプログラムは、標準ライブラリに含まれるDBXJSONユニットのクラスを使用して、JSONデータを解析してみました。
変更点だけを掲載しています。
uses DBXJSON;
procedure TMainForm.Button1Click(Sender: TObject);
var
json: string;
so: TJSONObject;
Percent: Extended;
Saving: Boolean;
begin
DateLabel.Caption := FormatDateTime('yyyy年m月d日 hh:nn:ss', now);
json := http.Get('http://tepco-usage-api.appspot.com/latest.json');
so := TJSONObject.ParseJSONValue(json) as TJSONObject;
saving := (so.Get('saving').JsonValue is TJSONTrue);
if saving then
SavingLabel.Caption := '実施'
else
SavingLabel.Caption := '非実施';
UsageLabel.Caption := so.Get('usage').JsonValue.Value;
CapacityLabel.Caption := so.Get('capacity').JsonValue.Value;
try
percent := StrToFloat(UsageLabel.Caption) / StrToFloat(CapacityLabel.Caption);
except
PercentLabel.Caption := '?';
Exit;
end;
PercentLabel.Caption := Format('%.0f', [percent*100]);
end;
uses superobjectは
JSON – SuperObjectをダウンロードするのでしょうか?
http://code.google.com/p/superobject/downloads/list
からダウンロードできます。
json := http.Get(‘http://tepco-usage-api.appspot.com/latest.json’);
が通らないのですが、なにが足りないでしょうか?
すみません、動作できました。