這是從我的瀏覽器視圖:尋找解析援助
{
"data": {
"request": [{
"query": "Lat 41.85 and Lon -87.65",
"type": "LatLon"
}],
"time_zone": [{
"localtime": "2012-02-14 16:05",
"utcOffset": "-6.0"
}]
}
}
現在,我使用這個代碼解析它:
function getTimeZone(latlong) {
jQuery(document).ready(function ($) {
$.ajax({
url: "http://www.worldweatheronline.com/feed/tz.ashx?key=[removed]&q=" + latlong + "&format=json",
dataType: "jsonp",
success: function (parsed_json) {
console.log(parsed_json.time_zone.utcOffset);
return parsed_json.time_zone.utcOffset;
},
error: function (parsed_json) {
//console.log("Error: " + parsed_json);
}
});
});
}
每次我運行代碼,我得到此錯誤:
Uncaught TypeError: Cannot read property 'utcOffset' of undefined
任何援助將不勝感激。
查看的數據顯示到控制檯(只複製我感興趣的部分):
Result:
Object
data: Object
request: Array[1]
time_zone: Array[1]
0: Object
localtime: "2012-02-14 16:46"
utcOffset: "-6.0"
結果: 對象 數據:對象 請求:數組[1] 的time_zone:數組[1 ] 0:對象 localtime:「2012-02-14 16:39」 utcOffset:「-6.0」 看起來它正在接收正確的數據。 – Kruug 2012-02-14 22:40:09
在Chrome/FF + Firebug中,您可以在JS控制檯中獲得一個很好的嵌套樹顯示,這樣您就可以瀏覽該對象並更好地瞭解它的結構。 – jka6510 2012-02-14 22:43:02
我發佈的是Chrome控制檯顯示的內容。 – Kruug 2012-02-14 22:46:08