1.書き方
2.取得
- [参考資料] PHPでJSONデータの取得の仕方
https://qiita.com/fantm21/items/603cbabf2e78cb08133e
3.出力
- [参考資料] PHPでJSONを出力して、JavaScriptで取得する方法
http://dot-town-lab.com/laboratory/item/24
4.コード
<?php /** * [livedoor Weather Hacks APIで、 * お天気データのJSONを取得するための1次細分区(cityタグ)の * 地域id一覧まとめ] * https://www.kaden1000.com/2013/04/livedoor-weather-hacks1%E6%AC%A1%E7%B4%B0%E5%88%86%E5%8C%BA%EF%BC%88city%E3%82%BF%E3%82%B0%EF%BC%89%E3%81%AE%E5%9C%B0%E5%9F%9Fid%E4%B8%80%E8%A6%A7%E3%81%BE%E3%81%A8%E3%82%81/ */ // file_get_contentsを使用する準備として、変数に格納。 $url = "http://weather.livedoor.com/forecast/webservice/json/v1?city=140010"; // ファイルの内容を全て文字列に読み込む $json = file_get_contents($url); // 文字エンコーディングを「UTF-8」変換する $json = mb_convert_encoding($json, 'UTF8', 'ASCII,JIS,UTF-8,EUC-JP,SJIS-WIN'); // JSON形式から連想配列形式へと変換 ( = デコード処理) $arr = json_decode($json,true);