English 中文(简体)
世界银行 JSONP 惩罚
原标题:World Bank JSONP Parsing

这应该非常直截了当,但即便是看着其他问题,我也不能让它工作。

I m 检索一些来自以下链接的世界银行数据:

该网络的结构如下:

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(){

怎样才能使国家受益? 感谢。

最佳回答

做过检测,但像现在这样做的就是trick。

function getWorldBankData(json){
    var item;
    var itemArray = json[1];
    for (var i in itemArray ) {
        item = itemArray[i];
        $( #category ).append("<option>"+ item.country.value+"</option>");
    };
}
问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签