【发布时间】:2019-02-19 12:30:20
【问题描述】:
我有一个 Json 对象,它有 4 个子对象:项目、第 1 列、第 2 列、第 3 列。
{
Item: {0: "PD", 1: "1 - Processor Intel Xeon E5-2630", 2: "2 - Additional
Processor", 3: "3 - Memory Quantity Increase", 4: "4 - Raid 6 H730/H730p Cabled Chassis", 5: "5 - Hard Drive Quantity Increase", 6: "6 - Perc H730 Raid Controller 1GB", 7: "7 - UEFI BIOS Boot", 8: "8 - Support: ProDeploy", 9: "9 - Hard Drive Support 3 years", 10: "10 - Dell Networking N2024P Switch", 11: "11 - N2024P Switch - 5 Years Support", 12: "12 - N2024P Switch - Pro Deployment L2 N"},
Column 1: {0: 0.2, 1: 0.64, 2: 0.67, 3: 0.63, 4: 0.65, 5: 0.74, 6: 0.64, 7: 0.65, 8: 0.63, 9: 0.65, 10: 1.02, 11: 0.71, 12: 0.7},
Column 2: {0: 0.24, 1: 0.7, 2: 0.69, 3: 0.7, 4: 0.69, 5: 0.79, 6: 0.69, 7: 0.68, 8: 0.67, 9: 0.68, 10: 1.05, 11: 0.74, 12: 0.72},
Column 3: {0: 0.199, 1: 0.665, 2: 0.652, 3: 0.631, 4: 0.644, 5: 0.698, 6: 0.647, 7: 0.637, 8: 0.622, 9: 0.63, 10: 0.997, 11: 0.698, 12: 0.672}
}
我需要捕获列名(对象名)并在编排模式下访问所有对象的第 th 个元素。例如:
项目:PD |第 1 列:0.2 |第 2 列:0.24 |第 3 列:0.199
项目:1 - 处理器 Intel Xeon E5-2630 |第 1 列:0.64 |第 2 列:0.7 |第 3 列:0.665
注意:Column 1、Column 2和Column 3的名称是动态的,创建这个json对象时可以是任意名称。
其他信息:
我正在使用 Javascript,我尝试仅在第一个对象中执行循环并为其他对象获取相同的位置单元格,但由于其他对象的名称是动态的,我不知道该怎么做。
i = 0
for (column in dfJson){
if(i == 0){
for (item in column){
console.log(dfJson['Item'][dfJson[obj][item]]); //here I have the value for the first object "Item" in this iteration
//here I need to collect the value for Column 1 in this same position
//here I need to collect the value for Column 2 in this same position
//here I need to collect the value for Column 3 in this same position
}i++;}}
【问题讨论】:
-
艾伦,请添加您尝试使用的语言和示例代码。您尝试过但没有成功的方法。
-
谢谢,在原始主题中添加了此信息。
标签: javascript json nested-loops