zoukankan      html  css  js  c++  java
  • 多层josn数据 修改

    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));

  • 相关阅读:
    常用的算法
    2017前端面试题
    深入了解php opcode缓存原理
    0=='aa'的结果是true
    关于PHP浮点数之 intval((0.1+0.7)*10) 为什么是7
    linux grep命令
    linux awk命令详解
    PHP socket模拟POST请求
    shell编程之sed
    Shell脚本常用判断
  • 原文地址:https://www.cnblogs.com/lgjc/p/9843094.html
Copyright © 2011-2022 走看看