我使用下面的代碼獲取了JSON數據。以PHP格式獲取數組數據
$json = file_get_contents('http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139');
$data = json_decode($json,true);
print_r($data);
foreach($data as $key => $datas){
$datas[$key];
}
這是解碼JSON
Array(
[coord] => Array
(
[lon] => 139
[lat] => 35
)
[sys] => Array
(
[message] => 0.0053
[country] => JP
[sunrise] => 1394571511
[sunset] => 1394614136
)
[weather] => Array
(
[0] => Array
(
[id] => 802
[main] => Clouds
[description] => scattered clouds
[icon] => 03d
)
)
[base] => cmc stations
[main] => Array
(
[temp] => 289.82
[pressure] => 1013
[temp_min] => 289.82
[temp_max] => 289.82
[humidity] => 30
)
[wind] => Array
(
[speed] => 3.08
[gust] => 8.74
[deg] => 230
)
[clouds] => Array
(
[all] => 48
)
[dt] => 1394611401
[id] => 1851632
[name] => Shuzenji
[cod] => 200
)
然後我試圖顯示使用foreach方法的數據,但我無法得到它的權利。
是否有人可以幫我這個.......
請給我們更多的信息。你期望什麼,發生了什麼? –
請提供您的'foreach'代碼。 –
'$ json'顯示什麼? –