百度了一下,找了点别人的方法改进了一下。 
获取天气网址: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. java网格布局管理器

    public class GirdLayoutPosition extends JFrame{    public GirdLayoutPosition()    {        Container ...

  2. linux下USB转串口驱动的安装

    ubuntu10.04,usb串口用的是moxa 1110 搞了半天没有驱动... 去官方下了个:http://www.moxa.com/support/sarch_result.aspx?type= ...

  3. 《Code Complete》ch.8 防御式编程

    WHAT? 主要思想:子程序不应因传入参数错误而被破坏 WHY? 保护程序免遭非法输入的破坏 HOW? 断言 assert denominator != 0 : "denominator s ...

  4. Redis单机版安装与部署

    Redis官网:http://redis.io 下载Redis wget https://github.com/antirez/redis/archive/3.0.0-rc1.tar.gz 解压并安装 ...

  5. 转载KMP

    出处: http://www.ruanyifeng.com/blog/2013/05/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm.html 在假期之前,断 ...

  6. 如何实现从Android第三方平台推送微信公众号

    最近心血来潮,想要尝试写写有关实现Android平台第三方应用软件去跳转到微信平台的代码.我只是先暂时写写我的思路,如后期实现,便将主要代码附上. 微信公众平台官方宣布微信沟通接口正式上线,用户可以在 ...

  7. [HTML5] document.hidden

    特殊说明: 通过document.hidden属性,可判断页面是否可见. 如果不可见,则document.hidden为true. 如果可见, 则为false. 但是, 如果该页面只是被其它窗口挡住, ...

  8. 【转载】Myeclipse如何自动创建hibernate

    Myeclipse如何自动创建hibernate:http://jingyan.baidu.com/article/456c463b99f4370a583144a8.html An internal ...

  9. webpack基础+webpack配置文件常用配置项介绍+webpack-dev-server

    一.webpack基础 1.在项目中生成package.json:在项目根目录中输入npm init,根据提示输入相应信息.(也可以不生成package.json文件,但是package.json是很 ...

  10. php接口post提交方法 。

    方法一,用 file_get_contents function send_post($url, $post_data) { //$postdata = http_build_query($post_ ...