循环遍历多维JSON数组并在javascript中获取值

时间:2017-05-05 20:19:06

标签: javascript arrays json multidimensional-array

我创建了一个JSON对象,其中包含两个数组。我在网上搜索了如何提取数据,但我尝试过的所有代码都返回了“undefined”或[object object]。

请你看看我的例子并告诉我如何做到这一点?

<html>
 <head>
     <title> New Document </title>
  <meta name="Generator" content="NPP-Plugin">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
 </head>
 <body>
 <div id="file"></div>
 <div id="applicID"></div>
  <script type="text/javascript">
var IETMObj = {
    "allItems": [{ 
         "sFile": "Test.html",
         "Applicability": [{   // second dimension
                            "ApplicID": "subj_1",
                            "ApplicDisp": "Driving",
                            "Condition": "In rain"
                    },{
                            "ApplicID": "subj_2",
                            "ApplicDisp": "Running",
                            "Condition": "Uphill"
                    }]
            }]
  };

  for (var i = 0; i < IETMObj.length; i++){
      document.write("<br><br>array index: " + i);
  var obj = IETMObj[i];
  for (var key in obj){
    var value = obj[key];
    document.write("<br> - " + key + ": " + value);
  }
}


  </script>
 </body>
</html>

0 个答案:

没有答案