百度了一下,找了点别人的方法改进了一下。 
获取天气网址: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. Eclipse设置模板代码

    1. 打开preferences,找到Java > Editor > Templates.2. 点击"New",新建一个模版: 3. 打开Java文件,输入模版名称的前 ...

  2. 21.Merge Two Sorted Lists(链表)

    Merge two sorted linked lists and return it as a new list. The new list should be made by splicing t ...

  3. 菜鸟-手把手教你把Acegi应用到实际项目中(6)

    在企业应用中,用户的用户名.密码和角色等信息一般存放在RDBMS(关系数据库)中.前面几节我们采用的是InMemoryDaoImpl,即基于内存的存放方式.这节我们将采用RDBMS存储用户信息. Us ...

  4. android softinput 相关

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN | WindowManager.Layo ...

  5. Hadoop2.6.0(2.4~2.7)完全分布式搭建-入门向 新手向 详细流程

    .caret,.dropup>.btn>.caret{border-top-color:#000 !important}.label{border:1px solid #000}.tabl ...

  6. port-channel和channel-group

    cisco交换机上的链路聚合 2层 ethernet channel (interface)#channel-group number mode {on | auto [no-silent]|desi ...

  7. java中sesion

    Session     *Cookie基于客户端,不安全,并且大小和个数的限制.     *Session域对象,范围一次会话范围,存个人相关的数据.     *setAttribute(String ...

  8. Java之注解

    package com.demo.test; import java.lang.annotation.Documented; import java.lang.annotation.ElementTy ...

  9. Anaconda日志

    https://fedoraproject.org/wiki/Anaconda/Logging Anaconda日志 centos7 anaconda安装日志目录 /var/log/anaconda ...

  10. nagios plugin 开发

    https://nagios-plugins.org/doc/guidelines.html#DEVREQUIREMENTS https://blog.centreon.com/good-practi ...