一聚教程网:一个值得你收藏的教程网站

热门教程

jQuery获取天气API实例程序代码

时间:2022-06-25 17:42:11 编辑:袖梨 来源:一聚教程网


1、后台
if(isset($_GET['city']) && $_GET['city']!='')
{
 $url='http://m.weather.com.cn/data/';
 $city=(int)$_GET['city'];
 $json = file_get_contents($url . $city .'.html');
 echo $json;
 exit;
}

获取http://m.weather.com.cn/data/的天气数据,返回的是json格式数据。

2、前台

返回的json数据:

weatherinfo:
{
city: "杭州"
city_en: "hangzhou"
cityid: "101210101"
date: ""
date_y: "2012年8月12日"
fchh: "18"
fl1: "小于3级"
fl2: "小于3级"
fl3: "小于3级"
fl4: "小于3级"
fl5: "小于3级"
fl6: "小于3级"
fx1: "微风"
fx2: "微风"
img1: "1"
img2: "4"
img3: "1"
img4: "99"
img5: "1"
img6: "4"
img7: "0"
img8: "1"
img9: "0"
img10: "1"
img11: "1"
img12: "99"
img_single: "4"
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: "雷阵雨"
index: "炎热"
index48: "炎热"
index48_d: "天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。"
index48_uv: "中等"
index_ag: "较易发"
index_cl: "较不宜"
index_co: "很不舒适"
index_d: "天气炎热,建议着短衫、短裙、短裤、薄型T恤衫、敞领短袖棉衫等清凉夏季服装。"
index_ls: "不宜"
index_tr: "一般"
index_uv: "中等"
index_xc: "不宜"
st1: "34"
st2: "26"
st3: "36"
st4: "26"
st5: "33"
st6: "27"
temp1: "26℃~35℃"
temp2: "27℃~35℃"
temp3: "27℃~35℃"
temp4: "28℃~35℃"
temp5: "28℃~36℃"
temp6: "28℃~35℃"
tempF1: "78.8?~95?"
tempF2: "80.6?~95?"
tempF3: "80.6?~95?"
tempF4: "82.4?~95?"
tempF5: "82.4?~96.8?"
tempF6: "82.4?~95?"
weather1: "多云转雷阵雨"
weather2: "多云"
weather3: "多云转雷阵雨"
weather4: "晴转多云"
weather5: "晴转多云"
weather6: "多云"
week: "星期日"
wind1: "微风"
wind2: "微风"
wind3: "微风"
wind4: "微风"
wind5: "微风"
wind6: "微风"
}

例子



weather API



获取杭州天气(来源:m.weather.com.cn)




热门栏目