首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

如何样判断JSON是不是为空啊

2014-01-01 
怎么样判断JSON是不是为空啊。。function CreateSelect(cid,parentid) {$.getJSON(GetItemCates.ashx?cid

怎么样判断JSON是不是为空啊。。
   


function CreateSelect(cid,parentid) {
    $.getJSON("GetItemCates.ashx?cid=" + cid, function (data) {
        var datas = data.itemcats_get_response.item_cats.item_cat;

        if (typeof (datas) != 'undefined') {

            GetItemCats(cid, parentid, datas);
        }
        else {
            alert('错误');
        }
    });
}





 反正就是不执行ELSE里面的内容。。。


浏览器提示错误 data.itemcats_get_response.item_cats is undefined

我的json为空的时候返回的是这个  {"itemcats_get_response":{}} 



怎么让他为空的时候弹出信息呢?
[解决办法]
那你就判断是否等于{"itemcats_get_response":{}}
[解决办法]
{"itemcats_get_response":{}} 

你返回的是json数组?

数组就判断.length

单个json对象 就json.mcats_get_response的值
[解决办法]
  var datas = data.itemcats_get_response 
if(data.itemcats_get_response == undefined)
alert('空');
[解决办法]
if(data && data !=null){
    //其它操作
}

热点排行