<?php
echo "<h1>What's The Weather Like?</h1>";
define('API_KEY','********');
$apikey = API_KEY;
$user_ip = '183.91.3.13'; // Remove comment to use this to test when you put
this file in localhost
//$user_ip = $_SERVER['REMOTE_ADDR']; // Comment out this line if you test
in your localhost
$details =
json_decode(file_get_contents("http://ipinfo.io/{$user_ip}/json"));
$city_name = $details->city;
$loc_details =
json_decode(file_get_contents("http://dataservice.accuweather.com/locations/v1/ cities/search?q={$city_name}&apikey={$apikey}"));
$loc_key = $loc_details[0]->Key;
$weather_details =
json_decode(file_get_contents("http://dataservice.accuweather.com/forecasts/v1/daily/1day/{$loc_key}?apikey={$apikey}"));
// print_r($weather_details);
// $result = json_decode($data, true);
echo $weather_details[0]->EffectiveDate;
?>
私はそれがこの問題 致命的なエラーを示しウェブ実行しよう:型のオブジェクトを使用することはできませんがCでの配列としてはstdClass:あなたは(json_decode
を使用して)PHPでJSONをデコードするとき、私は致命的なエラー:Cでの配列としてのタイプはstdClassのオブジェクトを使用することはできません: xamppの htdocsに AIW index.phpを
取得したJSON出力の例を提供します。また、一般的にあなたのAPIキーを公開することはお勧めできません。空の文字列や星の行に置き換えてください。 – Flying