Json 调用 天气API 实例
百度了一下,找了点别人的方法改进了一下。
获取天气网址:http://www.weather.com.cn/html/weather/101210701.shtml这里是温州的,当然其他城市自己搜索一下,换一下ID。
由于是写入cookies记录当天天气,所有需要在站点下浏览。
js代码:
var COOKIE_info = "COOKIE_info";
var date = new Date();
var Hours=24-date.getHours()-1;
var Mins=60-date.getMinutes()-1;
var Secs=60-date.getSeconds();
date.setTime(date.getTime() + (1 * Hours * 60 * 60 * 1000) + (1 * 1 * Mins * 60 * 1000) + (1 * 1 * 1 * Secs * 1000));
var RD_cookie_info= $.cookie(COOKIE_info);
$(function(){
if(RD_cookie_info==null)
{
Getdata(Url);
}
else{
$("#weather").html(RD_cookie_info);
}
})
function Getdata(Url)
{
$.ajax({
type:"GET",
cache: "false",
url: "AjaxGet.asp",
data:"Url="+Url,
dataType: "html",
error: function(){$("#weather").html("读取失败...请刷新重试!");},
success: function(json){
var t = '('+json+')';
var result = eval(t);
var Getinfo="";
Getinfo+=result.weatherinfo.date_y+" ";//年月日
Getinfo+=result.weatherinfo.date+" ";//农历年月日
Getinfo+=result.weatherinfo.week+" ";//星期几
Getinfo+="<br />";//换行
Getinfo+=result.weatherinfo.city;//获取城市名称
Getinfo+=" <img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img1+".gif\"/> "//天气图片1
Getinfo+="<img src=\"http://m.weather.com.cn/img/c"+result.weatherinfo.img2+".gif\"/> ";//天气图片2
Getinfo+=result.weatherinfo.weather1+" ";//天气情况
Getinfo+=result.weatherinfo.temp1;//温度
$.cookie(COOKIE_info,Getinfo, { path: '/', expires: date });
$("#weather").html(Getinfo);
}
});
}
html代码:
这个是用网络上常见的asp抓取,当然也可以换成.net抓取或者其他。附上demo。
Json 调用 天气API 实例的更多相关文章
- 调用天气Api实现天气查询
上面是简单截图: 前台代码: @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name=&qu ...
- jsonp 调用天气API
由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socket通讯 ...
- 控制台调用天气API例子
第一步,新建控制台应用程序,然后新建类:WeatherReport: using System; using System.Collections.Generic; using System.Linq ...
- 闲着无聊时写的一个调用天气 API 的小 Demo
分为两个部分--调用以及实现,并且由于不想折腾,直接使用了 Console 来调用. 通过firefox直接调用 Main 入口,调用以及输出 调用部分没什么好说的,主要是针对 dynamic 类型的 ...
- 天气api接口
python调用天气api接口: http://www.sojson.com/open/api/weather/json.shtml?city=北京 http://www.sojson.com/blo ...
- JAVA的免费天气api接口调用示例
step1:选择本文所示例的接口"免费天气api" url:https://www.juhe.cn/docs/api/id/39/aid/87 step2:每个接口都需要传入一个参 ...
- 雅虎天气API调用
雅虎天气API调用: 1.调用方法:http://weather.yahooapis.com/forecastrss?w=2502265&u=c,绿色字体为城市代号,u=c表示取摄氏度. 2. ...
- .net 调用java rest ful api 实例
注意post的参数组合 HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = &quo ...
- 解析和风天气API的json(objective-C实现)
暑假在家闲着没事干,心血来潮想做个天气预报APP玩玩,听说和风天气API很好,于是注册并试了下,结果它的JSON是这样的(拿我的家乡武义为例子) {"}},"status" ...
随机推荐
- sql查询,如何增加一列
select * from (select 'finish_order_info' as table_name,count(1)as num from fraudorder.finish_order_ ...
- QTEmbedded VCN实现
1 在QT在第三方插件里加入VNC 进入\src\plugins\gfxdrivers\vnc,qmake -------make--------- make install 把目标文件夹gfxdri ...
- Activity代码结构
把一个Nova项目中典型的Activity代码结构简单归纳一下,保持代码风格的一致,有助于日常开发效率提升以及日后维护 Class Name 变量 constants requests ...
- Android 在程序中动态添加 View 布局或控件
有时我们需要在程序中动态添加布局或控件等,下面用程序来展示一下相应的方法: 1.addView 添加View到布局容器 2.removeView 在布局容器中删掉已有的View 3.LayoutPar ...
- (Loadrunner)Error: Failed to send data by channels - post message failed.(转)
把Diagnotics-configure-Web Page Diagnotics 设置为 转自: http://www.51testing.com/html/64/371664-3708254.ht ...
- Unity WebSocket(仅适用于WebGL平台)
!!!转载注明:http://www.cnblogs.com/yinlong1991/p/unity_ylwebsocket.html Unity WebSocket 使用 1.下载 YLWebSoc ...
- (转载)MonoBehaviour的事件和具体功能总结
分享一点MonoBehaviour的事件和具体功能总结的基础知识,苦于Visual Studio 2013没有对MonoBehaviour的行为做出智能提示,写个函数都要全手打,记性好的将就着手打,脑 ...
- DB2 Magazine 中文版: 访问 iSeries 数据
当您第一次开始学习 DB2 for iSeries 时,一下子要弄清楚如何访问所有数据可能有些令人生畏.我将介绍访问 DB2 for iSeries 数据的一些常见的方法,并展示如何开始开发访问存储在 ...
- C#基础知识点
一.方法(结构.数组.冒泡排序.3个参数重载) 1将string转换为int类型 Convert.ToInt32(); int.Parse() ; int.TryParse()三种方式. 2 结构:可 ...
- C# 清空sessin
Session.Abandon();//清除全部Session//清除某个SessionSession["UserName"] = null;Session.Remove(&quo ...