js 递归多维数组解析成一维数组


 

function json_recursion (jsons,newjson){ // jsons 是你要解析的多维json或数组,  newjson 是改变后的值
for(var x in jsons){
if(jsons[x] instanceof Object||jsons[x] instanceof Array){
json_recursion (jsons[x],newjson);
}else{
newjson[x]=jsons[x]; //赋值给新json
}
}

}
var arr = [{"name":"王家三少","xldigitid":123456,"topscore":2000,"topplaytime":"2009-08-20"},{"xlid":"zd","xldigitid":123456,"topscore":1500,"topplaytime":"2009-11-20"}];
var newjson = {};
jsonrecursion  (arr,newjson);
console.log(newjson);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM