Javascript Angular JS中的嵌套JSON解析

Javascript Angular JS中的嵌套JSON解析,javascript,json,angularjs,Javascript,Json,Angularjs,下面给出了我的JSON。我想使用第二列、第三列、第四列,它们是成行的 { "workflows":[ { "New":{ "All":{ "sections":[ { "id":"section_1", "section":"",

下面给出了我的JSON。我想使用第二列、第三列、第四列,它们是成行的

{  

   "workflows":[  
      {  
         "New":{  
            "All":{  
               "sections":[  
                  {  
                     "id":"section_1",
                     "section":"",
                     "title":"SEPG Audit Checklist",
                     "rows":[  
                        {  
                            "id" : "0",
                            "label" : "How do you establish and maintain the description of the process needs and objectives for the organization?",
                            "2ndCol" : {
                                "type" : "select",
                                "source":[  
                                      {  
                                         "id":"Yes",
                                         "value":"Yes"
                                      },
                                      {  
                                         "id":"No",
                                         "value":"No"
                                      },
                                      {  
                                         "id":"N/A",
                                         "value":"N/A"
                                      }
                                ],
                                "value":[],
                                "required":true,
                                "disabled":false,
                                "hidden":false
                            },
                            "3rdCol" : {
                                "type" : "select",
                                "source":[  
                                      {  
                                         "id":"Yes",
                                         "value":"Yes"
                                      },
                                      {  
                                         "id":"No",
                                         "value":"No"
                                      }

                                ],
                                "value":[],
                                "required":true,
                                "disabled":false,
                                "hidden":false
                            },
                            "4thCol" : {
                                "type" : "textarea",
                                "label": "Comments",
                                "PlaceHolder":"Enter Comment",
                                "Value":""
                            }
                        },
                        {  
                            "id" : "1",
                            "label" : "Explain Organizational process performance objectives?",
                            "2ndCol" : {
                                "type" : "select",
                                "source":[  
                                      {  
                                         "id":"Yes",
                                         "value":"Yes"
                                      },
                                      {  
                                         "id":"No",
                                         "value":"No"
                                      },
                                      {  
                                         "id":"N/A",
                                         "value":"N/A"
                                      }
                                ],
                                "value":[],
                                "required":true,
                                "disabled":false,
                                "hidden":false
                            },
                            "3rdCol" : {
                                "type" : "select",
                                "source":[  
                                      {  
                                         "id":"Yes",
                                         "value":"Yes"
                                      },
                                      {  
                                         "id":"No",
                                         "value":"No"
                                      }

                                ],
                                "value":[],
                                "required":true,
                                "disabled":false,
                                "hidden":false
                            },
                            "4thCol" : {
                                "type" : "textarea",
                                "label": "Comments",
                                "PlaceHolder":"Enter Comment",
                                "Value":""
                            }
                        }
                         ]
                  }
               ]

            }
         }
      }
   ]
}
我可以使用id,行的标签。但当我尝试使用第二列、第三列和第四列时。它显示未捕获的异常非法参数

我的角度控制器

angular.forEach($scope.auditJSON.workflows, function(workflow, workflowIndex) {
                    angular.forEach(workflow, function(workflowValue, workflowKey) {
                        angular.forEach(workflowValue, function(value, roleKey) {
                            angular.forEach(value.sections, function(section, sectionIndx) {
                                angular.forEach(section.rows, function(row, rowIndx) {  

                                    console.log(row.label); // It shows fine

                                    console.log(row.2ndCol.type); // It shows the Error

                                });
                            });
                        });
                    });
                });

我想不出这些问题

你的
棱角分明。forEach
有点乱

angular.forEach($scope.data, function (workflow, workflowIndex) {
        angular.forEach(workflow, function (workflowValue, workflowKey) {
            angular.forEach(workflowValue, function (value, roleKey) {
                angular.forEach(value, function (sections, sectionIndx) {
                    angular.forEach(sections, function (section, rowIndx) {
                        angular.forEach(section, function (row, rowIndx) {
                            angular.forEach(row, function (row, rowIndx) {
                                if (rowIndx === 'rows') {
                                    angular.forEach(row, function (row, rowIndx) {
                                        var row2 = row['2ndCol'];
                                        var row3 = row['3rdCol'];
                                        console.log(row2, row3);
                                    });
                                }
                            });
                        });
                    });
                });
            });
        });
    });

实际上,我已经创建了一个回购协议,这样你就可以看到它是如何运作的。另外,请不要在您的产品中使用太多的
forEach

编辑:

你写下你想要得到2ndCol和3rdCol类型的值[你写在注释中]

 console.log(row.2ndCol.type); // It shows the Error
您还可以编写显示错误的代码。 我给出了代码块。这应该行得通

angular.forEach($scope.auditJSON.workflows, function(workflow, workflowIndex) {
                angular.forEach(workflow, function(workflowValue, workflowKey) {
                    angular.forEach(workflowValue, function(value, roleKey) {
                        angular.forEach(value.sections, function(section, sectionIndx) {
                            angular.forEach(section.rows, function(row, rowIndx) {  
                                    if(row['2ndCol'].type === 'select' && row['3rdCol'].type === 'select'){
                                        if(row['2ndCol'].value != row['3rdCol'].value){
                                            console.log(row['2ndCol'].value);
                                            console.log(row['3rdCol'].value);
                                        }
                                    }

                            });
                        });
                    });
                });
            });

如果它解决了你的问题,接受它作为答案

你想用这个做什么
ng repeat
将为您完成大部分循环。通过使用ng repeat,我以html呈现数据。但我需要控制器中2ndCol,3rdCol的值用于其他目的。为什么这一行[0]。行在这里?我只是选择第一行作为示例。但我需要动态选择所有行。我已更新了答案,但如果您解释您尝试执行的操作,将非常容易。您可以使用行['2ndCol'].value来获取值