我有一个Json对象。Json键remarks
和address
为空。如果它们为空,则在提取Json时打印undefine
。但是我想用-
符号替换空的Json。我知道我可以使用:
if(msg.hasOwnProperty('remarks')== ""){
alert("A");
}
如何遍历所有键并检查其是否为空,然后用-
替换而不是逐个检查。
[
{
"id": "224",
"booking_id": "1",
"room_type": null,
"no_of_rooms_booked": null,
"check_in_date": "2014-12-23",
"check_out_date": "2014-12-24",
"room_id": "93",
"hotel_id": "9",
"status": "1",
"user_id": "15",
"payment_type": "",
"payment_status": "",
"hotelname": "sample hotel",
"hoteladdress": "sample address",
"hotelcontact": "056533977",
"Id": "224",
"full_name": "Hom Nath Bagale",
"address": "",
"occupation": "Student",
"nationality": "Nepali",
"contact_no": "9845214140",
"email": "bhomnath@salyani.com.np",
"remarks": "",
"total_amount": "5000",
"child": "0",
"adult": "1",
"verification_code": null,
"roomname": "sample room2",
"roomprice": "1.5",
"roomdescription": "this is for demo",
"roomimage": "2.jpg"
}]
for(var key in x)
循环 - undefined