4.気象庁の天気予報APIとは?
4-1.WebAPIとは
Web APIとは、コンピュータプログラムの提供する機能を外部の別のプログラムから
呼び出して利用するための手順・規約(API:Application Programming Interface)
の類型の一つで、HTTPなどWebの技術を用いて構築されたもの。ざっくり簡単に言うと
オンライン上でアプリケーションを利用する、というものでデータが欲しい!!等のリクエスト
を送ったりするとデータがjsonやxml形式で返ってきます。これをAPIを叩くと言います。
4-2.気象庁の天気予報API
以下のURLにブラウザで直接アクセスすれば、JSONデータを確認できます。
・三重県の天気予報を取得する
https://www.jma.go.jp/bosai/forecast/data/forecast/240000.json
[{"publishingOffice":"津地方気象台","reportDatetime":"2022-06-07T11:00:00+09:00","timeSeries":[{"timeDefines":["2022-06-07T11:00:00+09:00","2022-06-08T00:00:00+09:00","2022-06-09T00:00:00+09:00"],"areas":[{"area":{"name":"北中部","code":"240010"},"weatherCodes":["201","201","101"],"weathers":["くもり 時々 晴れ","くもり 昼前 まで 時々 晴れ","晴れ 時々 くもり"],"winds":["西の風 海上 では 北西の風 やや強く","西の風 後 北西の風","東の風"],"waves":["0.5メートル","0.5メートル","0.5メートル"]},{"area":{"name":"南部","code":"240020"},"weatherCodes":["211","111","101"],"weathers":["くもり 夕方 から 晴れ","晴れ 昼過ぎ から くもり","晴れ 時々 くもり"],"winds":["北の風 海上 では 北西の風 やや強く","北の風 後 南の風","北の風 後 南の風"],"waves":["2.5メートル 後 2メートル","1.5メートル","1.5メートル"]}]},{"timeDefines":["2022-06-07T12:00:00+09:00","2022-06-07T18:00:00+09:00","2022-06-08T00:00:00+09:00","2022-06-08T06:00:00+09:00","2022-06-08T12:00:00+09:00","2022-06-08T18:00:00+09:00"],"areas":[{"area":{"name":"北中部","code":"240010"},"pops":["10","10","0","0","10","0"]},{"area":{"name":"南部","code":"240020"},"pops":["0","0","0","0","20","20"]}]},{"timeDefines":["2022-06-07T09:00:00+09:00","2022-06-07T00:00:00+09:00","2022-06-08T00:00:00+09:00","2022-06-08T09:00:00+09:00"],"areas":[{"area":{"name":"津","code":"53133"},"temps":["24","24","17","26"]},{"area":{"name":"尾鷲","code":"53378"},"temps":["26","26","15","24"]},{"area":{"name":"四日市","code":"53061"},"temps":["24","24","14","24"]},{"area":{"name":"上野","code":"53112"},"temps":["24","24","13","25"]}]}]},{"publishingOffice":"津地方気象台","reportDatetime":"2022-06-07T11:00:00+09:00","timeSeries":[{"timeDefines":["2022-06-08T00:00:00+09:00","2022-06-09T00:00:00+09:00","2022-06-10T00:00:00+09:00","2022-06-11T00:00:00+09:00","2022-06-12T00:00:00+09:00","2022-06-13T00:00:00+09:00","2022-06-14T00:00:00+09:00"],"areas":[{"area":{"name":"三重県","code":"240000"},"weatherCodes":["201","101","201","200","200","201","202"],"pops":["","20","40","40","30","20","50"],"reliabilities":["","","B","C","B","B","C"]}]},{"timeDefines":["2022-06-08T00:00:00+09:00","2022-06-09T00:00:00+09:00","2022-06-10T00:00:00+09:00","2022-06-11T00:00:00+09:00","2022-06-12T00:00:00+09:00","2022-06-13T00:00:00+09:00","2022-06-14T00:00:00+09:00"],"areas":[{"area":{"name":"津","code":"53133"},"tempsMin":["","18","19","19","19","18","19"],"tempsMinUpper":["","19","20","20","20","20","21"],"tempsMinLower":["","16","18","17","17","16","18"],"tempsMax":["","25","25","23","27","26","22"],"tempsMaxUpper":["","27","27","27","29","28","25"],"tempsMaxLower":["","23","23","21","25","24","20"]}]}],"tempAverage":{"areas":[{"area":{"name":"津","code":"53133"},"min":"19.0","max":"25.6"}]},"precipAverage":{"areas":[{"area":{"name":"津","code":"53133"},"min":"24.6","max":"57.4"}]}}]
JSONなので人間には少し読みにくいですが、読みやすくする方法はあります。
Firefoxブラウザを使うと分かりやすく表示してくれます。
気象庁jsonデータの仕様は、この様な感じです。
次の章で、天気予報表示プログラムの解説を行います。