amt: "10.00"
email: "sam@gmail.com"
merchant_id: "sam"
mobileNo: "9874563210"
orderID: "123456"
passkey: "1234"
以上就是我要处理的JSON对象。我想检查merchant_id键是否存在。我尝试了下面的代码,但它不工作。有办法实现吗?
<script>
window.onload = function getApp()
{
var thisSession = JSON.parse('<?php echo json_encode($_POST); ?>');
//console.log(thisSession);
if (!("merchant_id" in thisSession)==0)
{
// do nothing.
}
else
{
alert("yeah");
}
}
</script>
函数检查未定义和空对象
function elementCheck(objarray, callback) {
var list_undefined = "";
async.forEachOf(objarray, function (item, key, next_key) {
console.log("item----->", item);
console.log("key----->", key);
if (item == undefined || item == '') {
list_undefined = list_undefined + "" + key + "!! ";
next_key(null);
} else {
next_key(null);
}
}, function (next_key) {
callback(list_undefined);
})
}
这是一个简单的方法来检查对象发送是否包含未定义或空
var objarray={
"passenger_id":"59b64a2ad328b62e41f9050d",
"started_ride":"1",
"bus_id":"59b8f920e6f7b87b855393ca",
"route_id":"59b1333c36a6c342e132f5d5",
"start_location":"",
"stop_location":""
}
elementCheck(objarray,function(list){
console.log("list");
)
函数检查未定义和空对象
function elementCheck(objarray, callback) {
var list_undefined = "";
async.forEachOf(objarray, function (item, key, next_key) {
console.log("item----->", item);
console.log("key----->", key);
if (item == undefined || item == '') {
list_undefined = list_undefined + "" + key + "!! ";
next_key(null);
} else {
next_key(null);
}
}, function (next_key) {
callback(list_undefined);
})
}
这是一个简单的方法来检查对象发送是否包含未定义或空
var objarray={
"passenger_id":"59b64a2ad328b62e41f9050d",
"started_ride":"1",
"bus_id":"59b8f920e6f7b87b855393ca",
"route_id":"59b1333c36a6c342e132f5d5",
"start_location":"",
"stop_location":""
}
elementCheck(objarray,function(list){
console.log("list");
)