dostaję z powrotem następujące JSON:JavaScript: Jak sprawdzić, czy odpowiedź JSON tablica jest pusta
{"array":[],"object":null,"bool":false}
A ja sprawdzając je za pomocą następujących, pozornie wyczerpująca, if:
$.ajax({
type: "GET",
url: "/ajax/rest/siteService/list",
dataType: "json",
success: function (response) {
var siteArray = response.array;
// Handle the case where the user may not belong to any groups
if (siteArray === null || siteArray=== undefined || siteArray=== '' || siteArray.length === 0) {
window.alert('hi');
}
}
});
Ale alert nie uruchamia się. : [
Co pokazuje "console.log (siteArray)"? – Dennis
[]. Próbowałem jeśli siteArray === "[]", ale to nie zadziałało ani – Lurk21
Pusta tablica nie jest taka sama jak 'null',' undefined', i in. – Phrogz