æè¿å¨åå¾®ä¿¡å ¬ä¼å¹³å°æµè¯æ¶ï¼æ³å¨éé¢åèåä¸æ·»å æ¥è¯¢æªæ¥å 天ï¼å æ¬ä»å¤©ï¼å¤©æ°çåè½ï¼å°±æ¥æ¾äºä¸å¥½ç¨ç天æ°é¢æ¥æ¥è¯¢æ¥å£APIï¼ä½¿ç¨æ¯è¾å¤çæï¼å½å®¶æ°è±¡å±å¤©æ°æ¥å£ãæ°æµªå¤©æ°é¢æ¥æ¥å£ãç¾åº¦å¤©æ°é¢æ¥æ¥å£ãgoogle天æ°æ¥å£ãYahoo天æ°æ¥å£ççï¼æ使ç¨çæ¯ç¾åº¦æä¾çå 费天æ°æ¥è¯¢æ¥å£APIï¼ä¸é¢ä¸å¤§å®¶å享ä¸...
1ãæ¥è¯¢æ¹å¼ï¼
ç¾åº¦æä¾çæ¯æ ¹æ®çº¬åº¦ååå¸åæ¥è¯¢å¤©æ°æ åµ
2ãæ¥å£äºä¾ï¼
3ãæ¥å£åæ°è¯´æï¼
4ãè¿åç»æ说æï¼
5ã
//åå¸å
$city = 'ä¸æµ·';
//对jsonæ ¼å¼çå符串è¿è¡ç¼ç
$arr =json_decode($str,TRUE);
print_r($atr);
//åå¸å6ãè¿å页é¢çæ¯jsonç¼ç åçæ°æ®ï¼
[plain] view plain copy print?
<meta charset="UTF-8">
Array
(
[error] => 0
[status] => success
[date] => 2014-03-17
[results] => Array
(
[0] => Array
(
[currentCity]=> ä¸æµ·
[weather_data]=> Array
(
[0]=> Array
(
[date] => å¨ä¸(ä»å¤©, å®æ¶ï¼19â)
[dayPictureUrl] =>http://api.map.baidu.com/images/weather/day/qing.png
[nightPictureUrl] =>http://api.map.baidu.com/images/weather/night/qing.png
[weather] => æ´
[wind] => 西åé£3-4级
[temperature] => 13â
)
[1] => Array
(
[date]=> å¨äº
[dayPictureUrl] =>http://api.map.baidu.com/images/weather/day/duoyun.png
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/yin.png
[weather]=> å¤äºè½¬é´
[wind]=> ä¸åé£3-4级
[temperature] => 24 ~ 9â
)
[2] => Array
(
[date]=> å¨ä¸
[dayPictureUrl] =>http://api.map.baidu.com/images/weather/day/zhongyu.png
[nightPictureUrl] => http://api.map.baidu.com/images/weather/night/xiaoyu.png
[weather]=> ä¸é¨è½¬å°é¨
[wind]=> ä¸åé£3-4级
[temperature] => 15 ~ 8â
)
[3] => Array
(
[date]=> å¨å
[dayPictureUrl] =>http://api.map.baidu.com/images/weather/day/duoyun.png
[nightPictureUrl] =>http://api.map.baidu.com/images/weather/night/qing.png
[weather]=> å¤äºè½¬æ´
[wind]=> åé£3-4级
[temperature] => 14 ~ 6â
)
)
)
)
)
<meta charset="UTF-8">7ãPHPä¸èªå¸¦äºå¤çjsonæ ¼å¼å符串çå ç½®å½æ°ï¼ä¸é¢åä¸ä¸ªäºä¾ï¼å¹¶ç»åºå®æ´ä»£ç ï¼
[php] view plain copy print?
<metacharset="UTF-8">
<?php
//åå¸å
$city = 'ä¸æµ·';
//è·åjsonæ ¼å¼çæ°æ®
$str = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=".$city."&output=json&ak=5slgyqGDENN7Sy7pw29IUvrZ");
//对jsonæ ¼å¼çå符串è¿è¡ç¼ç
$arr = json_decode($str,TRUE);
echo "åå¸:".$arr['results'][0]['currentCity']." æ¥æï¼".$arr['date']."<br /><br />";
foreach($arr['results'][0]['weather_data']as $val)
{
echo $val['date']."<br/>";
echo "天æ°ï¼{$val['weather']}<br/>";
echo "é£åï¼{$val['wind']}<br/>";
echo "温度ï¼{$val['temperature']}<br/><br />";
}
?>
<metacharset="UTF-8">8ãè¿åçå 容å¦ä¸ï¼