JS解析JSON多层嵌套的数据集 var x = { "monthFactoryWaitingRateDataList": [ { "factory": "HZC01", "dayFactoryWaitingRateList": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], "days": [ "2023-04-01", "2023-04-02", "2023-04-03", "2023-04-04", "2023-04-05", "2023-04-06", "2023-04-07", "2023-04-08", "2023-04-09", "2023-04-10", "2023-04-11", "2023-04-12", "2023-04-13", "2023-04-14", "2023-04-15", "2023-04-16", "2023-04-17", "2023-04-18", "2023-04-19", "2023-04-20", "2023-04-21", "2023-04-22", "2023-04-23", "2023-04-24", "2023-04-25", "2023-04-26", "2023-04-27", "2023-04-28", "2023-04-29", "2023-04-30" ], "dayStrs": [ "04-01", "04-02", "04-03", "04-04", "04-05", "04-06", "04-07", "04-08", "04-09", "04-10", "04-11", "04-12", "04-13", "04-14", "04-15", "04-16", "04-17", "04-18", "04-19", "04-20", "04-21", "04-22", "04-23", "04-24", "04-25", "04-26", "04-27", "04-28", "04-29", "04-30" ] }, { "factory": "HZC02", "dayFactoryWaitingRateList": [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], "days": [ "2023-04-01", "2023-04-02", "2023-04-03", "2023-04-04", "2023-04-05", "2023-04-06", "2023-04-07", "2023-04-08", "2023-04-09", "2023-04-10", "2023-04-11", "2023-04-12", "2023-04-13", "2023-04-14", "2023-04-15", "2023-04-16", "2023-04-17", "2023-04-18", "2023-04-19", "2023-04-20", "2023-04-21", "2023-04-22", "2023-04-23", "2023-04-24", "2023-04-25", "2023-04-26", "2023-04-27", "2023-04-28", "2023-04-29", "2023-04-30" ], "dayStrs": [ "04-01", "04-02", "04-03", "04-04", "04-05", "04-06", "04-07", "04-08", "04-09", "04-10", "04-11", "04-12", "04-13", "04-14", "04-15", "04-16", "04-17", "04-18", "04-19", "04-20", "04-21", "04-22", "04-23", "04-24", "04-25", "04-26", "04-27", "04-28", "04-29", "04-30" ] } ] }; //var data1 = x.monthFactoryWaitingRateDataList[0] var data0 = Object.keys(x)[0] var data1 = Object.values(x)[0][1] var data2 = Object.keys(Object.values(x)[0][0]) var data3 = Object.keys(Object.values(x)[0][0]) let column = []; column.push(data2); let content = []; // for (let i=0; i< data1.dayFactoryWaitingRateList.length;i++){
for (let j =0 ; j<Object.values(Object.values(x)[0][0])[1].length;j++){ let contentLine = []; content.push(Object.values(Object.values(x)[0][0])[0],Object.values(Object.values(x)[0][0])[1][j],Object.values(Object.values(x)[0][0])[2][j],Object.values(Object.values(x)[0][0])[3][j]); //var zd1 = Object.keys(Object.values(x)[0][0]).slice(0,[1]); } for (let values of $data.result){ var contentLine = []; content.push(Object.values(values)) } //content.push(data1.dayFactoryWaitingRateList) //let column = []; //for (let i=0; i< data1.dayFactoryWaitingRateList.length;i++){ //column.push(`col${i + 1}`); //} //result = {} //result.column = column; //result.content = content; // return result; //console.log(result); //console.log(Object.values(Object.values(x)[0][0])[1].length); console.log(content); |