function Recursion(node){ var count=0; for (var key in node) { count++; var value = node[key]; delete node[key]; //如果node为叶子节点 if (key.toString() == '$') { for (var attr in value) node[attr] = value[attr]; } else { if (value instanceof Array) { if (value.length > 0) { node["children"] = value; for (var obj in value) Recursion(value[obj]); } } } } if(count==1) node["children"]=[]; } function randomString(len) { len = len || 32; var $chars = 'abcdefhijkmnprstwxyz'; // 默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1 var maxPos = $chars.length; var pwd = ''; for (i = 0; i < len; i++) { pwd += $chars.charAt(Math.floor(Math.random() * maxPos)); } return pwd; } exports.randomString=randomString; exports.Recursion=Recursion;