var aa = {
a: 1,
b: {
c: 1,
d: 1
},
e: [{
f: 1,
g: 2
}, {
h: 1,
i: {
j: 3,
k: [{
l: 55,
m: [1, 2, 3, {
n: "dddd",
o: {
dd: 00,
ccc: ["c", "d", [1, 2, 3, {
a: 1111,
c: 111,
ddd: [1, 2, 3]
}]]
}
}]
}]
}
}]
};
var newJson = {};
console.time("a")
for(key in aa) {
newJson[key] = judgeData(aa[key]);
}
console.timeEnd("a")
console.log(JSON.stringify(newJson));
console.log("==========");
//判断数据类型
function judgeData(data) {
var newData;
//json
if(typeof(data) == "object" && Object.prototype.toString.call(data).toLowerCase() == "[object object]" && !data.length)
newData = encryptionJson(data);
//array
else if(data instanceof Array)
newData = encryptionArr(data);
else
//进行加密操作
newData = data + "---加密了";
return newData;
}
//加密数组
function encryptionArr(data) {
return data.map((value, index, arr) => {
return judgeData(value);
});
}
//加密json
function encryptionJson(data) {
var newJson = {};
for(key in data) {
newJson[key] = judgeData(data[key]);
}
return newJson;
}
console.log(Object.keys(aa));