2016-01-11 25 views
0

我有一個由九個完整記錄集組成的JSON文件,下面我列出了三個。如何使用AJAX返回我的JSON文件中的所有「名稱」值?

我的最終目標是將AJAX添加到網站,我的json文件中的信息目前直接列入html而不是通過AJAX列出。我提取並構建了通過AJAX使用它的JSON文件。

我想了解我應該如何去遍歷每個json對象並返回列出的每個「名稱」。

[{ 
    "name":"Keith Moore", 
    "link":"http://www.moorelife.org/freedownloads-serieslist.php?", 
    "image":"keith_moore.jpg", 
    "details":"Teacher/Pastor, I refer to Keith as my \"bible college experience,\" he has 30+ years of free audio and video available on any and every subject." 
}, 
    { 
    "name":"Kenneth Hagin", 
    "link":"https://www.youtube.com/playlist?list=PLIXcY2izjpDgROo3MRlAU2MJSyjthXLLc", 
    "image":"kenneth_hagin.jpg", 
    "details":"Prophet, with nearly 70 years of ministry under his belt, Hagin most commonly preached on the subject of faith in Gods word." 
}, 
    { 
    "name":"Bill Johnson", 
    "link":"https://www.youtube.com/playlist?list=PLEtP4XPKdli585uNfIU8WNRYawCusmEYK", 
    "image":"bill_johnson.jpg", 
    "details":"Apostle/Pastor, Bill pastors a church in Redding California named Bethel Church, the church is most known for miracles, signs and wonders." 
}] 

到目前爲止,這是我有什麼,但它不深入足夠的訪問名值

$(document).ready(function() { 
    $.getJSON("data/asdf.json", function(result) { 
    $.each(result, function(i, field) { 
     $("#update").append(field + " "); 
    }); 
    }); 
}); 

其報告如下,以我的HTML:

[對象的對象] [對象對象]對象對象對象對象對象對象對象對象對象對象對象對象對象對象

我在找的是一個起始塊inf ormation,它允許我開始爲我的JSON文件中列出的每個值構建函數。

+0

所有你想要做的就是輸出'每個對象的name'領域?你非常接近。在你傳遞'each'的函數中,'field'是一個對象。你可以像這樣訪問'name'屬性:'field.name'。完成。 – ordonezalex

回答

1

這行代碼正在訪問對象,而不是name屬性。

$("#update").append(field + " "); 

將其更改爲:

$("#update").append(field.name + " "); 
+0

這很完美,解決了我的問題 - 謝謝! – aronlmin

相關問題