最新天气预报接口【2015-05-14改】

今天一时兴起测试了天气接口,才发现接口失效了。于是重新找了下数据,发现居然原先接口地址的'data'被改成了'atad'

现在修改博客,保证接口正常。【2015年5月14日修

国家气象局链接例子:http://m.weather.com.cn/atad/101010100.html 【 101010100 为城市代码】

返回的数据是json数据。

{"weatherinfo":{"city":"北京","city_en":"beijing","date_y":"2015年5月14日","date":"","week":"星期四","fchh":"18","cityid":"101010100","temp1":"15℃~25℃","temp2":"11℃~28℃","temp3":"17℃~30℃","temp4":"16℃~28℃","temp5":"16℃~27℃","temp6":"14℃~28℃","tempF1":"59℉~77℉","tempF2":"51.8℉~82.4℉","tempF3":"62.6℉~86℉","tempF4":"60.8℉~82.4℉","tempF5":"60.8℉~80.6℉","tempF6":"57.2℉~82.4℉","weather1":"阴","weather2":"晴","weather3":"多云转雷阵雨","weather4":"阴转晴","weather5":"晴","weather6":"晴","img1":"2","img2":"99","img3":"0","img4":"99","img5":"1","img6":"4","img7":"2","img8":"0","img9":"0","img10":"99","img11":"0","img12":"99","img_single":"2","img_title1":"阴","img_title2":"阴","img_title3":"晴","img_title4":"晴","img_title5":"多云","img_title6":"雷阵雨","img_title7":"阴","img_title8":"晴","img_title9":"晴","img_title10":"晴","img_title11":"晴","img_title12":"晴","img_title_single":"阴","wind1":"微风","wind2":"微风转南风3-4级","wind3":"微风转南风3-4级","wind4":"微风转北风4-5级","wind5":"北风4-5级","wind6":"微风","fx1":"微风","fx2":"微风","fl1":"小于3级","fl2":"小于3级转3-4级","fl3":"小于3级转3-4级","fl4":"小于3级转4-5级","fl5":"4-5级","fl6":"小于3级","index":"舒适","index_d":"建议着长袖T恤、衬衫加单裤等服装。年老体弱者宜着针织长袖衬衫、马甲和长裤。","index48":"","index48_d":"","index_uv":"最弱","index48_uv":"","index_xc":"较适宜","index_tr":"适宜","index_co":"舒适","st1":"27","st2":"13","st3":"26","st4":"11","st5":"27","st6":"18","index_cl":"较适宜","index_ls":"不太适宜","index_ag":"易发"}}


php使用:

	$url = 'http://m.weather.com.cn/atad/101010100.html';
	$weather_json = file_get_contents($url);
	$weather = json_decode($weather_json);
	$info = $weather -> {'weatherinfo'};


城市代码:








你可能感兴趣的:(php)