'length'是null还是不是对象?IE 8

Sca*_*ace 7 javascript jquery internet-explorer

嘿伙计快速问题我在IE 8中得到以下错误'长度为空或不是对象',任何人都有任何想法?反馈非常感谢...

 function refresh() {
$.getJSON(files+"handler.php?action=view&load=update&time="+lastTimeInterval+"&username="+username+"&topic_id="+topic_id+"&t=" + (new Date()), function(json) {
    if(json.length) {
      for(i=0; i < json.length; i++) {
        $('#list').prepend(prepare(json[i]));
        $('#list-' + count).fadeIn(1500);
      }
      var j = i-1;
      lastTimeInterval = json[j].timestamp;
    }
  });

}
Run Code Online (Sandbox Code Playgroud)

Poi*_*nty 11

只需检查对象为null或为空:

if (json && json.length) {
  // ...
}
Run Code Online (Sandbox Code Playgroud)

来吧这显然非常明显:-)