本文介绍了如何阅读使用jQuery阿贾克斯雅虎天气JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

http://weather.yahooapis.com/forecastjson?w=2295424

  {
单位:
{温度:F,速度:英里,距离:MI,pressure:在},
"location":{"location_id":"INXX0075","city":"Madras","state_abbreviation":"*","country_abbreviation":"IN","elevation":49,"latitude":13,"longitude":80.18000000000001},
风声:{速度:12.00000000000000,方向:E},
大气:{湿度:23,可见性:4.35,pressure:29.77,上升:稳},
"url":"http:\/\/weather.yahoo.com\/forecast\/INXX0075.html","logo":"http:\/\/l.yimg.com\/a\/i\/us\/nt\/ma\/ma_nws-we_1.gif","astronomy":{"sunrise":"06:20","sunset":"18:19"},"condition":{"text":"Sunny","$c$c":"32","image":"http:\/\/l.yimg.com\/a\/i\/us\/we\/52\/32.gif","temperature":93.00000000000000},

预测:[{
天:今天,条件:天色灰蒙蒙,high_temperature:91,low_temperature:69},{天:明天,条件:晴间多云,high_temperature:90后,low_temperature:70}
]}
 

我要显示预测

解决方案

  $。阿贾克斯({
   网址:http://weather.yahooapis.com/forecastjson?w=2295424
   数据类型:JSON,
   成功:功能(数据){
      的console.log(data.forecast [0]·天);
      }
 });
 

在data.forecast [0]·天更换天有什么属性,你所需要的。

http://weather.yahooapis.com/forecastjson?w=2295424

{
"units":
{"temperature":"F","speed":"mph","distance":"mi","pressure":"in"},
"location":{"location_id":"INXX0075","city":"Madras","state_abbreviation":"*","country_abbreviation":"IN","elevation":49,"latitude":13,"longitude":80.18000000000001},
"wind":{"speed":12.00000000000000,"direction":"E"},
"atmosphere":{"humidity":"23","visibility":"4.35","pressure":"29.77","rising":"steady"},
"url":"http:\/\/weather.yahoo.com\/forecast\/INXX0075.html","logo":"http:\/\/l.yimg.com\/a\/i\/us\/nt\/ma\/ma_nws-we_1.gif","astronomy":{"sunrise":"06:20","sunset":"18:19"},"condition":{"text":"Sunny","code":"32","image":"http:\/\/l.yimg.com\/a\/i\/us\/we\/52\/32.gif","temperature":93.00000000000000},

"forecast":[{
"day":"Today","condition":"Mostly Clear","high_temperature":"91","low_temperature":"69"},{"day":"Tomorrow","condition":"Partly Cloudy","high_temperature":"90","low_temperature":"70"}
]}

I want to display "forecast"

解决方案
$.ajax({
   url: "http://weather.yahooapis.com/forecastjson?w=2295424",
   dataType: "json",
   success: function(data) {
      console.log( data.forecast[0].day );
      }
 });

In data.forecast[0].day you replace "day" with whatever property you need.

这篇关于如何阅读使用jQuery阿贾克斯雅虎天气JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 14:00