我在我的javascript中有这个方法,调用检索URL响应并计算JSON中的对象数。它假设返回值3,但它返回我63。我有什么不对的吗?
这是我的json
[
{
"crisisID": 1,
"name": "Test1",
"positionInCMO": "General",
"threatLevel": 4,
"crisisType": "Type1",
"affectedArea": "Area1",
"estimatedCasualties": 10000,
"crisisDuration": "Duration1",
"crisisDetails": "Detail1",
"courseOfAction": "Action1",
"consequencesOfAction": "Consequence1",
"cleanUpAction": "CleanUp1"
},
{
"crisisID": 2,
"name": "Test2",
"positionInCMO": "General",
"threatLevel": 5,
"crisisType": "Type2",
"affectedArea": "Area2",
"estimatedCasualties": 10000,
"crisisDuration": "Duration2",
"crisisDetails": "Detail2",
"courseOfAction": "Action2",
"consequencesOfAction": "Consequence2",
"cleanUpAction": "CleanUp2"
},
{
"crisisID": 3,
"name": "Test3",
"positionInCMO": "General",
"threatLevel": 4,
"crisisType": "Type3",
"affectedArea": "Area3",
"estimatedCasualties": 10000,
"crisisDuration": "Duration3",
"crisisDetails": "Detail3",
"courseOfAction": "Action3",
"consequencesOfAction": "Consequence3",
"cleanUpAction": "CleanUp3"
}
]
这是我的javascript代码
function checkForNotifications(){
$.ajax({
url: "http://localhost:8080/CMOtoPMO/proposal/",
type: "GET",
success: function(notification) {
//Check if any notifications are returned - if so then display alert
alert(Object.keys(notification).length);
},
error: function(data){
//handle any error
alert("Error");
}
});
}