我有一个包含一个数组的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 –