百度了一下,找了点别人的方法改进了一下。 
获取天气网址:http://www.weather.com.cn/html/weather/101210701.shtml这里是温州的,当然其他城市自己搜索一下,换一下ID。 
由于是写入cookies记录当天天气,所有需要在站点下浏览。 
js代码:

复制代码代码如下:
var Url=escape("http://m.weather.com.cn/data/101210701.html"); 
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代码:

复制代码代码如下:
<div id="weather" style="font-size:12px;"></div> 

这个是用网络上常见的asp抓取,当然也可以换成.net抓取或者其他。附上demo

Json 调用 天气API 实例的更多相关文章

  1. 调用天气Api实现天气查询

    上面是简单截图: 前台代码: @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name=&qu ...

  2. jsonp 调用天气API

    由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Socket通讯 ...

  3. 控制台调用天气API例子

    第一步,新建控制台应用程序,然后新建类:WeatherReport: using System; using System.Collections.Generic; using System.Linq ...

  4. 闲着无聊时写的一个调用天气 API 的小 Demo

    分为两个部分--调用以及实现,并且由于不想折腾,直接使用了 Console 来调用. 通过firefox直接调用 Main 入口,调用以及输出 调用部分没什么好说的,主要是针对 dynamic 类型的 ...

  5. 天气api接口

    python调用天气api接口: http://www.sojson.com/open/api/weather/json.shtml?city=北京 http://www.sojson.com/blo ...

  6. JAVA的免费天气api接口调用示例

    step1:选择本文所示例的接口"免费天气api" url:https://www.juhe.cn/docs/api/id/39/aid/87 step2:每个接口都需要传入一个参 ...

  7. 雅虎天气API调用

    雅虎天气API调用: 1.调用方法:http://weather.yahooapis.com/forecastrss?w=2502265&u=c,绿色字体为城市代号,u=c表示取摄氏度. 2. ...

  8. .net 调用java rest ful api 实例

    注意post的参数组合 HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = &quo ...

  9. 解析和风天气API的json(objective-C实现)

    暑假在家闲着没事干,心血来潮想做个天气预报APP玩玩,听说和风天气API很好,于是注册并试了下,结果它的JSON是这样的(拿我的家乡武义为例子) {"}},"status" ...

随机推荐

  1. SELinux配置不当导致vsftpd系统用户不能登陆

    1.测试是否是SELinux配置不当导致的: setenforce 0 再次登陆ftp,正常,说明是SELinux配置不当导致.还原配置 setenforce 1 2.查看配置: getsebool ...

  2. 用android:clipChildren来实现红心变大特效

    最近在看别人技术博客(http://www.cnblogs.com/over140/p/3508335.html)的时候,发现一个属性:android:clipChildren属性. 翻文档找到下面介 ...

  3. jdbc调用sparksql

    将hive-site.xml拷贝到spark目录下conf文件夹 local模式 spark-sql --driver-class-path /usr/local/hive-1.2.1/lib/mys ...

  4. 黑马程序员_Java基本数据的自动拆装箱及享元设计模式视频学习笔记

    ------- android培训.java培训.期待与您交流! ---------- 装箱:把基本数据类型装成java类(被托管?).         拆箱:把java类拆成基本数据类型(取消托管? ...

  5. 制作Win7(x86)PE ISO文件

    WinPE3.1     —Win7 x86 PE V3.1: waik_supplement_zh-cn.isoDVD: cn_windows_7_professional_with_sp1_x86 ...

  6. Android开发-API指南-应用程序开发基础

    Application Fundamentals 英文原文:http://developer.android.com/guide/components/fundamentals.html 采集(更新) ...

  7. Nodejs文件服务器

    最近一直在忙于一个比较大的项目,在项目中需要有个文件服务器来支持.老鸟们建议我去用NodeJs来实现,我在接手这个项目之前其实并不了解NodeJs,但是一直想去了解.借着这个机会好好去学习一下.下面是 ...

  8. Change screensaver through registry

    If you wanna change the screensaver, you can update registry as follows{autoit script}: RegWrite(&qu ...

  9. vb 取得桌面路径

    txtPath.Text = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop)

  10. Comparing cards

    For built-in types, there are conditional operators (<, >, ==, etc.) that compare values and d ...