如何检查是否JSON的回报是空与jQuery [英] How to check if JSON return is empty with jquery
本文介绍了如何检查是否JSON的回报是空与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$.getJSON(url, function(json) {
var output = '';
$.each(json, function(i,d) {
if(d.DESCRIPTION == 'null'){ console.log("Its empty");
}
var description = d.DESCRIPTION;
output += '<tr><td>'+d.NAME+'</td><td>'+'<tr><td>'+d.DESCRIPTION+'</td><td>';
});
});
我尝试添加了
I tried adding the
if(d.DESCRIPTION == 'null'){ console.log("Its empty");
要检查,如果返回的对象是空的,但它不能正常工作。
to check if the object returned is empty, but it doesn't work.
有人能向我解释什么不对的?
Can someone explain to me what's wrong with this?
推荐答案
只是测试如果数组是空的。
Just test if the array is empty.
$.getJSON(url,function(json){
if ( json.length == 0 ) {
console.log("NO DATA!")
}
});
这篇关于如何检查是否JSON的回报是空与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文