所以我從衛報API的開放平臺JSON格式的數據我想解析這個在jquery中,我當前堅持嘗試顯示結果到我的HTML div。衛報API,JSON解析jquery/javascript
數據的格式如下:Guardian JSON results
我的代碼,我試圖用是爲如下工作
function processFootballData(footballData){
footyStuff = footballData;
var thisContainer = document.getElementById("results");
var listTmp = document.createElement("ul");
var tmpList = "";
for(var i=0; (i<footyStuff.results[0].length) && (i<100); i++) {
if(tmpList.length <= 0) {
tmpList = footyStuff.results[0][ i ];
}
else {
tmpList = tmpList + "," + footyStuff.results[0][ i ];
}
}
var footballURL = "http://content.guardianapis.com/search?q=football&format=json&api-key=ky5zy8mds5r25syu36t9kmzj";
$.getJSON(footballURL,
function(thisData) {
var data = thisData;
for(var key in data) {
var thisSublist = document.createElement("ul");
thisSublist.setAttribute('style', "border-bottom: 1px solid #000; width: 80%;");
var thisItem = document.createElement("li");
var footyResults = data[key].results[0];
if(data.hasOwnProperty(key)) {
var duyList = document.createElement("li");
duyList.setAttribute('style', "padding-bottom: 10px;margin-top:-15px;margin-left:53px;font-size:12px;");
duyFooty = document.createTextNode(footyResults);
duyList.appendChild(duyFooty);
thisItem.appendChild(duyList);
}
thisItem.appendChild(thisSublist);
}
listTmp.appendChild(thisItem);
}
thisContainer.appendChild(listTmp);
});
}
你有沒有看着http://api.jquery.com/ jQuery.parseJSON/ –