Uncaught TypeError: Cannot read property 'DYMC' of null

    var arr = [null,{"ADDR":"","BZ":"","CZSJ":"","DYMC":"哈哈","FJH":"","GRMJ":"","GRQ":"","GRQF":0,"KH":"","LHMC":"","QFJE":0,"SFLX":"","TRQF":0,"XQMC":"","YHBH":"","YHLB":"","YHXM":"","ZNJ":0}]
for(var i in arr){
        console.log(arr[i].DYMC);
 }

报错

Uncaught TypeError: Cannot read property 'DYMC' of null
    at 1.html:13

原因数组遍历是因为有null
更改:

 var arr = [null,{"ADDR":"","BZ":"","CZSJ":"","DYMC":"哈哈","FJH":"","GRMJ":"","GRQ":"","GRQF":0,"KH":"","LHMC":"","QFJE":0,"SFLX":"","TRQF":0,"XQMC":"","YHBH":"","YHLB":"","YHXM":"","ZNJ":0}]
        for(var i in arr){
            if(arr[i]!=null){
                console.log(arr[i].DYMC);
            }
        }

你可能感兴趣的:(java,javascript,json,javascript,property)