天气预报接口 URL



http://m.weather.com.cn/atad/101020100.html


//当前上海天气预报URL

string urlValue= "http://m.weather.com.cn/atad/101020100.html";


//返回Json格式数据

 public TResult InvokeMethod<TResult>(string url)
        {
            using (WebClientChannel scope = new WebClientChannel(url))
            {
                return scope.Get<TResult>();
            }
        }



//URL返回值

{"weatherinfo":{"city":"上海","city_en":"shanghai","date_y":"2014年7月6日","date":"六月初十","week":"星期日","fchh":"11","cityid":"101020100","temp1":"29℃~23℃","temp2":"30℃~24℃","temp3":"30℃~24℃","temp4":"32℃~25℃","temp5":"33℃~25℃","temp6":"32℃~26℃","tempF1":"84.2℉~73.4℉","tempF2":"86℉~75.2℉","tempF3":"86℉~75.2℉","tempF4":"89.6℉~77℉","tempF5":"91.4℉~77℉","tempF6":"89.6℉~78.8℉","weather1":"阴","weather2":"小雨转多云","weather3":"多云","weather4":"多云","weather5":"多云","weather6":"多云转小雨","img1":"2","img2":"99","img3":"7","img4":"1","img5":"1","img6":"99","img7":"1","img8":"99","img9":"1","img10":"99","img11":"1","img12":"7","img_single":"2","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":"西北风3-4级","wind2":"东北风3-4级","wind3":"东北风3-4级","wind4":"西北风4-5级","wind5":"东风3-4级","wind6":"东南风3-4级","fx1":"西北风","fx2":"西北风","fl1":"3-4级","fl2":"3-4级","fl3":"3-4级","fl4":"4-5级","fl5":"3-4级","fl6":"3-4级","index":"热","index_d":"天气热,建议着短裙、短裤、短薄外套、T恤等夏季服装。","index48":"","index48_d":"","index_uv":"弱","index48_uv":"","index_xc":"不宜","index_tr":"适宜","index_co":"较舒适","st1":"29","st2":"20","st3":"27","st4":"22","st5":"29","st6":"22","index_cl":"较适宜","index_ls":"不太适宜","index_ag":"极不易发"}}

告别 iframe 和 Js调用的天气预报,这些天气预报插件大部分都有外连接,或者弹窗程序,调用速度也比较慢,样式也是由他们定制的,也许和您的网站外观很不匹配。 API天气预报插件的优点 1.使用专业api接口,获取数据快,可直接获取三天。 2.每次打开调用页面的时候并不获取天气信息,所以天气插件不会影响到您网站的速度。 3.每10--30分钟在net后台自动获取天气信息一次,不存在手动更新,很方便。 4.没有任何外连接。完全展示大站风采。 5.样式有自己掌握,想做成啥样式的天气预报都可以(图标也可以自己换)。 6.使用XML形式储存,基本上不占用网站资源。 7.已经写成专业类库,只需要 new一个类就可以使用了,略懂皮毛的也能运用自如。 其实我不分析大家也应该能感觉得到调用其他站点天气的痛苦,呵呵,所以才有了这个插件。 演示站点:http://www.hhhjw.com/ 首页右侧,点-查看详情 本插件完全免费使用,天气插件使用客户QQ群6774488 插件资源来自于网络,若此程序伤害到您的利益,请联系QQ130944520 使用方式简述: 第一步 用记事本打开网站根目录web.config,找到<appSettings>节点,插入:<add key="StationCity" value="泉州" /> 泉州是城市名称,不要带市。 第二步 根目录Global.asax.cs文件,引入:using PowerLabs.Plug.Api 命名空间; 找到 public class Global : System.Web.HttpApplication 在括号内第一行加上 private static bool inited = false; //要加上,控制字段 private static object initLocker = new object(); //要加上,互斥锁 找到protected void Application_BeginRequest(object sender, EventArgs e) 在括号内第一行加上 //加上以下代码 if (inited == false) { #region 初始化 lock (initLocker) //lock 关键字将语句块标记为临界区,方法是获取给定对象的互斥锁,执行语句,然后释放该锁。 { if (inited == false) { //启动天预报 WeatherXml.StartWeather(); //持续定义定时器,用来持续获取天气 WeatherXml.Init(); inited = true; } } #endregion } 以上2步已经回在您的网站Weather目录下更新了数据文件Weather.config(可以用记事本打开看) 第三步 页面调用。 任何页面才CS部分引入:using PowerLabs.Plug.Api 命名空间; 然后再人以位置加上以下代码就可以了。 WeatherModel myWeather = new WeatherModel(WeatherXml.getWeather()); 就是new一个我的天气 可以获得的字段 /// <summary> /// 省份 myWeather.Provinces /// </summary> /// <summary> /// 城市 myWeather.City /// </summary> /// <summary> /// 城市代码 myWeather.CityCode /// </summary> /// <summary> /// 城市图片名称 myWeather.CityImgName /// </summary> /// <summary> /// 接口更新时间 myWeather.ApiUpDateTime /// </summary> /// <summary> /// 今天气温 格式:13℃/25℃ myWeather.TodayTemperature /// </summary> /// <summary> /// 今天的日期和天气 格式:10月5日 晴 myWeather.TodayWeather /// </summary> /// <summary> /// 今天风向 myWeather.TodayWind /// </summary> /// <summary> /// 今天天气开始图标 myWeather.TodayStartIcon /// </summary> /// <summary> /// 今天天气结束图标 myWeather.TodayEndIcon /// </summary> /// <summary> /// 今天天气实况 myWeather.TodayTheWeather /// </summary> /// <summary> /// 今天室外各指数 myWeather.TodayOutdoor 这个是一个一位数组,不会使用看压缩包中的例子。 /// </summary> /// <summary> /// 明天气温 格式:13℃/25℃ myWeather.TomorrowTemperature /// </summary> /// <summary> /// 明天的日期和天气 格式:10月5日 晴 myWeather.TomorrowWeather /// </summary> /// <summary> /// 明天风向 myWeather.TomorrowWind /// </summary> /// <summary> /// 明天天气开始图标 myWeather.TomorrowStartIcon /// </summary> /// <summary> /// 明天天气结束图标 myWeather.TomorrowEndIcon /// </summary> /// <summary> /// 后天气温 格式:13℃/25℃ myWeather.AfterTemperature /// </summary> /// <summary> /// 后天的日期和天气 格式:10月5日 晴 myWeather.AfterWeather /// </summary> /// <summary> /// 后天风向 myWeather.AfterWind /// </summary> /// <summary> /// 后天天气开始图标 myWeather.AfterStartIcon /// </summary> /// <summary> /// 后天天气结束图标 myWeather.AfterEndIcon /// </summary> /// <summary> /// 本城市简介 myWeather.ThisCity /// </summary> 也可以在aspx文件直接调用,调用方式:获得今天气温:<%=myWeather.TodayTemperature%> 其他类似。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值