你將不得不使用$.each
或這樣的,假設Items
[]
有多個對象。 jQuery中有許多迭代函數,如map
和each
。選擇一個最適合您的需求。要選擇Items
[]
從jsonResponse
,請使用
var items = jsonResponse.Items;
這是一個each
功能將如何看起來像:
//empty array for your ids
var ids = [];
//each function for iteration
$.each(items, function(i, item) {
ids.push(item.id);
});
//done. now check if its all there
alert(JSON.stringify(ids));
或者你也可以使用for
循環:
//empty array for your ids
var ids = [], i=0;
//for loop for iteration
for(; i < items.length, i++)
{
ids.push(items[i].id);
};
//done. now check if its all there
alert(JSON.stringify(ids));
或者直接使用map
:
var ids = $.map(items, function(item, i) {
//return id from item object
return item.id;
});
歡迎堆棧溢出!爲了獲得最佳效果,請告訴我們您期望發生的事情,展示您嘗試的內容,並解釋該嘗試未能實現您的目標。 –
我可以給你很多鏈接[this](http://stackoverflow.com/questions/733314/jquery-loop-over-json-result-from-ajax-success),[this](http:// stackoverflow。 com/questions/10251772/loop-json-response-after-ajax-success)and [this](http://stackoverflow.com/questions/1208270/how-to-loop-through-my-json-response-using -jquery) –
alert(JSON.stringify(jsonResponse));我提醒了所有的數組值,但我需要檢索唯一的ID值 – user2615566