我们经常用在后端用json_encode($arr),之后输出给前段js使用

如:

...$.get('<?=current_url()?>',{page:page+1,action:'ajax'},function(data){if(data.list.length>0){$('#page').attr('page',page+1);_html='';$.each(data.list,function(x,y){_html+='<li>'+'<ahref="http://'+y.domain+'">'+'<imgsrc="/static/pf/demo/list_shop.gif">'+'</a>'+'</li>';})$('ul.shop_list').append(_html);}else{showAlert('没有更多了!');that.hide();}that.html('查看更多');},'json');...

chrome的控制台里居然报了个错,调试后得知data.list没有length这个属性,可是我在后端json_encode一个数组后js这里得到的data.list也是个数组才对,几番调试,居然json_encode这个函数在处理关联数组和非关联数组时得到的结果是不一样的。