我試圖從我的JSON響應訪問所需的值,以加載到下拉框中。但我得到undefined
作爲下拉項目。Reguarding訪問JSON響應的值
這裏是我的JSON響應:
{"currency":[{"code":"USD","dateModified":"2015-10-30T20:43:58","decimalPlace":"2","id":1,"status":true,"symbolLeft":"$","symbolRight":"","tiendayaOrderses":[],"title":"US Dollar","value":1.00000000},{"code":"EUR","dateModified":"2015-10-30T20:43:58","decimalPlace":"2","id":2,"status":true,"symbolLeft":"","symbolRight":"€","tiendayaOrderses":[],"title":"Euro","value":0.76775432},{"code":"GBP","dateModified":"2015-10-30T20:43:58","decimalPlace":"2","id":3,"status":true,"symbolLeft":"£","symbolRight":"","tiendayaOrderses":[],"title":"Pound Sterling","value":0.64524455}]}
這是我如何獲取我的迴應:
$(document).ready(function() {
$.ajax({
url: "currencies",
dataType: 'json',
error: function() {
alert('error');
},
success: function(data) {
//var jsonData = $.parseJSON(data);
$.each(data.currency, function(index) {
$.each(data.currency[index], function(key, value) {
//curncyDrop is the drop-down box
$('#curncyDrop').append('<li><a>' + value.title +
'</a></li>');
});
});
}
});
});
這會將所有數據所需要的下拉,而不是裝載(標題)值:
$('#curncyDrop').append('<li><a>' + value + '</a></li>');
在此先感謝。
什麼是嵌套的'each'報表?看起來你在響應中只有一個數組。 –