2
這應該是非常直截了當的,但即使看看其他問題,我也無法得到它的工作。世界銀行JSONP解析
我從以下鏈接獲取一些樣本世界銀行的數據:
這將返回以下JSONP結構:
getWorldBankData([
{
"page": 1,
"pages": 1,
"per_page": "100",
"total": 52
},
[
{
"indicator": {
"id": "DC.DAC.FINL.CD",
"value": "Net bilateral aid flows from DAC donors, Finland (current US$)"
},
"country": {
"id": "GB",
"value": "United Kingdom"
},
"value": null,
"decimal": "0",
"date": "2011"
},
{
"indicator": {
"id": "DC.DAC.FINL.CD",
"value": "Net bilateral aid flows from DAC donors, Finland (current US$)"
},
"country": {
"id": "GB",
"value": "United Kingdom"
},
"value": null,
"decimal": "0",
"date": "2010"
},
我希望得到國家的稱號。我曾試圖用下面的代碼可以這樣做:
function getWorldBankData(json){
$.each(json.country ,function(){
var country = "<option>"+this.value+"</option>"
$('#category').append(country)
});
}
,但我得到了以下錯誤:
a is undefined
f()jquery.min.js (line 16)
a = undefined
c = function()
d = undefined
getWorldBankData()oil.js (line 11)
json = [Object { page=1, pages=1, per_page="100", more...}, [Object { indicator={...}, country={...}, decimal="0", more...}, Object { indicator={...}, country={...}, decimal="0", more...}, Object { indicator={...}, country={...}, decimal="0", more...}, 49 more...]]
DC.DAC.FINL.CD?per_page=100&date=1960:2012&format=jsonP&prefix=getWorldBankData()DC.DAC...ankData (line 1)
[Break On This Error]
...all(b,0))}}var b=arguments,c=0,d=b.length,e=d,g=d<=1&&a&&f.isFunction(a.promise)...
它不喜歡這行(第11行):
$.each(json.country ,function(){
得到國家的正確方法是什麼?謝謝。
我不認爲json.country是去工作,因爲該數組的JSON更深一層。 – Ansari
謝謝,是的,我注意到,並試圖json..country,但沒有奏效。如何跳過空白級別? – user578582
克勞迪奧的答案可能有效:) – Ansari