2014-03-27 63 views

回答

1

使用jQuery移動解析來自任何API的數據。 請按照下面給出的代碼和示例JSON。

$.getJSON('ajax/test.json', function(data) { 
    var items = []; 

    $.each(data, function(key, val) { 
    items.push('<li id="' + key + '">' + val + '</li>'); 
    }); 

    $('<ul/>', { 
    'class': 'my-new-list', 
    html: items.join('') 
    }).appendTo('body'); 
}); 

This example, of course, relies on the structure of the JSON file: 

{ 
    "one": "Singular sensation", 
    "two": "Beady little eyes", 
    "three": "Little birds pitch by my doorstep" 
} 
+0

Sanawaj謝謝回答,但它是沒有多大用處的我,因爲我沒有得到它,認爲我一個絕對的初學者IM在學習階段,你可以張貼方法請求來自API的數據,特別是ajax請求方法,我已經提到了上面的網站已經 – user3467992

+0

你必須遵循jQuery Mobile tutorials.I'm給你一些鏈接。你也可以使用上面的方法在'ajax/test.json'的地方傳遞你的URL。 – Sanawaj

+0

感謝Sanawaj等待鏈接。其實我已經從你的答案中找出了答案,並且一些Google搜索功能基本上向API申請了一個$ get請求,它將我的城市代碼和APPID參數附加到apis Url並獲取結果,現在嘗試如何做到這一點 – user3467992