jquery - 如何使用 Jquery ajax 读取雅虎天气 JSON 数据

标签 jquery ajax json

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"}
]}

我想显示“预测”

最佳答案

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

在 data.forecast[0].day 中,您可以将“day”替换为您需要的任何属性。

关于jquery - 如何使用 Jquery ajax 读取雅虎天气 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5717087/

相关文章:

ajax - JSF,使用ajax定期刷新组件?

php - 如何使用 php ajax 从输出表中搜索数据

JQuery 下拉菜单列表

javascript - 优化 IE6 的字符串代码

在ajax之前点击设置输入的Javascript

java - Grails 无法接收序列化数据

ios - iOS 中的 itunes JSON 请求返回一个 XML 对象

json - 为什么在尝试使用 serde_json 解析数据时总是出现 "trailing characters"错误?

javascript - FullCalendar 获取多日事件的点击日期

jquery - 在 ajax 调用期间禁用链接的最佳方法是什么?