根據我以前的post,我試圖從使用JSON的RESTful接口獲取一些信息。我正在研究JQuery 1.5。JSON返回的未定義的值
我面臨的問題是,我回來了未定義的值。我無法使用firebug,因爲我的應用程序是使用PhoneGap開發的,並且該應用程序正在iPhone的模擬器上運行。
如果我訪問RESTful接口(I型在瀏覽器中的「example.json」網址 - 這裏的例子是其他開發人員創建了一個有效的URL)返回我下面的格式結果:
[{"person":{"created_at":"2011-07-18T17:51:33Z","id":1,"name":"John","age":60,"surname":"Smith","car_id":1,"updated_at":"2011-07-18T17:51:33Z"}},{"person":{"created_at":"2011-07-18T17:51:35Z","id":1,"name":"Johnny","age":50,"surname":"Deep","car_id":2,"updated_at":"2011-07-18T17:51:35Z"}}]
我需要獲取信息ID,名稱,年齡並將它們存儲在數組中(而不是HTML表格)。只是爲了看看連接返回任何值,我使用的代碼:
var jqxhr = $.getJSON("example.json", function(person) {
$.each(person, function(i, person) {
alert(person.name);
alert(person.age);
});
})
.success(function() { alert("second success"); })
.error(function() { alert("Cannot connect to the SWT's maps. Please try again later!"); })
.complete(function() { alert("complete"); });
那麼,爲什麼會被警告未定義的值?
你編輯你的問題? – ChristopheCVB
@Christophe是的,我輸入錯誤,現在這正是我的代碼的樣子。 – tasanoui
所以Fabrizio是對的 – ChristopheCVB