如何在多个数组中检查json对象?

时间:2017-03-21 07:43:45

标签: javascript jquery json

我在ajax响应中接收到multiples数组,我想检查一下我可以显示状态结果的具体响应。我在响应中有以下json数组

{
    "registration_ids": ["fY-werwrwewer:APwerwermjl1rGUCxFhr_NixJxRucZ-dr_XoBONbacp_UXTcMAWiXKrGLCJwerwerCdKESdUsVyYM7W33"],
    "message": "There is New Event, tap to view.",
    "data": {
        "registration_ids": ["fY-werwrwewer:APwerwermjl1rGUCxFhr_NixJxRucZ-dr_XoBONbacp_UXTcMAWiXKrGLCJwerwerCdKESdUsVyYM7W33"
        ],
        "message": "There is New Event, tap to view.",
        "action": "event",
        "user_type": "all"
    }
} {
    "multicast_id": 24432423829565,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0,
    "results": [{
        "error": "NotRegistered"
    }]
} 
{
    "noti_success": "Notification has been sent to users."
}

我想使用这个noti_success对象来显示消息,但它不起作用,我检查了两种模式。

    success: function(response){
       if(response.hasOwnProperty('noti_success'){
$(".top_nav").prepend('<div>'+response.noti_success+'</div>');
        }
     }

和这个

success: function(response){
           if(response.noti_success){
    $(".top_nav").prepend('<div>'+response.noti_success+'</div>');
            }
         }

但是上述两种模式都不起作用,任何人都可以指导我是否有可能找到noti_success我可以显示回复。如果有人指导我,我想感谢。谢谢

1 个答案:

答案 0 :(得分:-1)

此JSON语法错误

JSON值可以是数组,对象或基元(数字或字符串)。

[{

    "registration_ids": ["fY-werwrwewer:APwerwermjl1rGUCxFhr_NixJxRucZ-dr_XoBONbacp_UXTcMAWiXKrGLCJwerwerCdKESdUsVyYM7W33"],
    "message": "There is New Event, tap to view.",
    "data": {
        "registration_ids": ["fY-werwrwewer:APwerwermjl1rGUCxFhr_NixJxRucZ-dr_XoBONbacp_UXTcMAWiXKrGLCJwerwerCdKESdUsVyYM7W33"
        ],
        "message": "There is New Event, tap to view.",
        "action": "event",
        "user_type": "all"
    },
 "status":{
    "multicast_id": 24432423829565,
    "success": 0,
    "failure": 1,
    "canonical_ids": 0
}
}]