這是天氣json的數據,這里是鏈接,json的數據接口 http://m.weather.com.cn/data/101010100.html
json的數據格式
{"weatherinfo":{"city":"北京","city_en":"beijing","date_y":"2014年3月4 日","date":"","week":"星期二","fchh":"11","cityid":"101010100","temp1":"8℃~- 3℃","temp2":"8℃~-3℃","temp3":"7℃~-3℃","temp4":"8℃~- 1℃","temp5":"10℃~1℃","temp6":"10℃~2℃","tempF1":"46.4℉~26.6℉","tempF2":"46.4℉~26.6℉","tempF3":"44.6℉~26.6℉","tempF4":"46.4℉~30.2℉","tempF5":"50℉~33.8℉","tempF6":"50℉~35.6℉","weather1":" 晴","weather2":"晴","weather3":"晴","weather4":"晴轉多雲","weather5":"多 雲","weather6":"多 雲","img1":"0","img2":"99","img3":"0","img4":"99","img5":"0","img6":"99","img7":"0","img8":"1","img9":"1","img10":"99","img11":"1","img12":"99","img_single":"0","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":"北風4-5級轉微風","wind2":"微風","wind3":"微 風","wind4":"微風","wind5":"微風","wind6":"微風","fx1":"北風","fx2":"微 風","fl1":"4-5級轉小於3級","fl2":"小於3級","fl3":"小於3級","fl4":"小於3級","fl5":"小於3 級","fl6":"小於3級","index":"寒冷","index_d":"天氣寒冷,建議着厚羽絨服、毛皮大衣加厚毛衣等隆冬服裝。年老體弱者 尤其要注意保暖防凍。","index48":"冷","index48_d":"天氣冷,建議着棉服、羽絨服、皮夾克加羊毛衫等冬季服裝。年老體弱者宜 着厚棉衣、冬大衣或厚羽絨服。","index_uv":"中等","index48_uv":"中等","index_xc":"較適 宜","index_tr":"一般","index_co":"較舒適","st1":"7","st2":"- 3","st3":"8","st4":"0","st5":"7","st6":"-1","index_cl":"較不 宜","index_ls":"基本適宜","index_ag":"易發"}}
這里是什么不用說了吧
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Json跨域解決辦法</title>
<script src='http://code.jquery.com/jquery-1.8.0.js' type='text/javascript'></script>
<script type="text/javascript" src="https://github.com/douglascrockford/JSON-js/blob/master/json2.js"></script>
</head>
<body>
<div id="content">
</div>
<script>
$(function () {
$.getJSON("http://query.yahooapis.com/v1/public/yql", {
q: "select * from json where url=\"http://m.weather.com.cn/data/101010100.html\"",
format: "json"
}, function (data) {
if (data.query.results) {
$("#content").text(JSON.stringify(data.query.results));
var J_data = JSON.parse(JSON.stringify(data.query.results));
alert(J_data.weatherinfo.city);
} else {
$("#content").text('no such code: ' + code);
}
});
});
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Json跨域解決辦法</title>
<script src='http://code.jquery.com/jquery-1.8.0.js' type='text/javascript'></script>
<script type="text/javascript" src="https://github.com/douglascrockford/JSON-js/blob/master/json2.js"></script>
</head>
<body>
<div id="content">
</div>
<script>
$(function () {
$.getJSON("http://query.yahooapis.com/v1/public/yql", {
q: "select * from json where url=\"http://m.weather.com.cn/data/101010100.html\"",
format: "json"
}, function (data) {
if (data.query.results) {
$("#content").text(JSON.stringify(data.query.results));
var J_data = JSON.parse(JSON.stringify(data.query.results));
alert(J_data.weatherinfo.city);
} else {
$("#content").text('no such code: ' + code);
}
});
});
</script>
</body>
</html>