我有一個包含一個數組的json響應,在該數組內我有一個更多的數組。如何在foreach循環內獲取jQuery的foreach值
我的AJAX:
$.ajax({
type: "POST",
data: { city: city, priceRange: range },
url: "rentpriceRangeFilter.php",
success: function(data) {
var res = jQuery.parseJSON(data); // convert the json
console.log(res);
if (res['status'] == 1) {
var htmlString = '';
$.each(res['data'], function(key, value) {
console.log(key + ' is ' + value.house);
});
}
},
});
rentpriceRangeFilter.php(我返回JSON響應)
echo json_encode(array("status"=>"1","response"=>"success","data"=>$mainArray));
我的JSON響應這樣的:
{
"status": "1",
"response": "success",
"data": [{
"id": "2",
"house": "1 BHK Apartment for Lease",
"rentLease_amount": "6000000",
"furnished_type": "Semi-Furnished",
"CreatedOn": null,
"Rent": "60 Lac",
"multipleImages": [{
"imageId": "3",
"rentImageId": "2",
"rentImageName": "2cf011438e6cd43c6bfaa6cac653d86e.jpg"
}, {
"imageId": "4",
"rentImageId": "2",
"rentImageName": "e2c5be420130370c5118120a1bc749c6.jpg"
}]
}, {
"id": "1",
"house": "1 BHK Aparatment for Marathahalli",
"rentLease_amount": "500000",
"furnished_type": "Fully-Furnished",
"CreatedOn": null,
"Rent": "5 Lac",
"multipleImages": [{
"imageId": "1",
"rentImageId": "1",
"rentImageName": "7d2905c30ab211732b97dbf165c75526.jpg"
}, {
"imageId": "2",
"rentImageId": "1",
"rentImageName": "bcf6cb343aaa2cc8e50ff52baa062bcc.jpg"
}]
}]
}
現在我想顯示house
名稱和multipleImages
值,但在我的ajax頁面,我只能得到房子名稱,我不怎麼顯示multipleImages
。
遺漏的類型錯誤:無法讀取的不確定 –
@@穆罕默德HAMEDANI,我想你的代碼我收到錯誤 –
我更新了我的答案財產「圖像標識」,請嘗試再次。 @subikshanM –