自定義方法如下:
ergodicJSON = funtion(jsonData){
for(var da in jsonData){
if(typeof jsonData[da] != "object"){
console.log(da+":"+jsonData[da])
}else{
if(Object.prototype.toString.call(jsonData[da])=="[object Array]"){
//數組類型的子實體
ergodicJSON (jsonData[da][0],array,parentName+'.'+da);
}else{
//複雜類型的子實體
ergodicJSON (jsonData[da],array,parentName+'.'+da);
}
}
}
}
主要涉及的方法: typeof obj 和 Object.prototype.toString.call(obj),第一個比較泛,第二個比較詳細。
type of 對於複雜對象和數組均設置爲:object,
Object.prototype.toString.call 對於複雜對象和對象數組分別爲:"[object Object]" 、"[object Array]"