Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Javascript将包含关联键值的文本文件转换为数组并显示在html表中_Javascript_Html_Arrays - Fatal编程技术网

使用Javascript将包含关联键值的文本文件转换为数组并显示在html表中

使用Javascript将包含关联键值的文本文件转换为数组并显示在html表中,javascript,html,arrays,Javascript,Html,Arrays,文本文件包含以下数组 [ { "title":"Test Report", "htmlpath":"C:\\sample.html", "browser":"phantomjs", "browser_version":"2.1.1", "time":"0h 0min 0s5", "testresults":"passed: 1 failed: 0 skipped: 2" } ] [ {

文本文件包含以下数组

[  
   {  
      "title":"Test Report",
      "htmlpath":"C:\\sample.html",
      "browser":"phantomjs",
      "browser_version":"2.1.1",
      "time":"0h 0min 0s5",
      "testresults":"passed: 1 failed: 0 skipped: 2"
   }
]

[  
   {  
      "title":"Test Report",
      "htmlpath":"C:\\sample1.html",
      "browser":"internet explorer",
      "browser_version":"11",
      "time":"0h 0min 0s8",
      "testresults":"passed: 1 failed: 0 skipped: 2"
   }
]
我想使用Javascript阅读上面的文本文件,将其解析为关联数组。 使用此数组并为键值对创建一个表,并在HTML中显示。
请使用现有代码帮助实现此目的。

首先,您需要一台服务器才能读取文件。浏览器不允许直接访问文件系统(这将是一个巨大的安全问题)

使用NodeJS,您可以读取和解析文本文件中的JSON,如下所示:

readFile("mydata.json", (error, text) => console.log( JSON.parse(text) ) )

然后,迭代json数据,并使用您想要的任何框架(jQuery、Angular等)构建一个表。

这应该是每个对象的两个数组吗?显示如何读取文件您的工作是什么??你写了什么代码?这不是免费的编码服务;人们通常不愿意仅仅为您编写程序。如果你展示你已经尝试过的东西,或者提供一些证据表明你至少尝试过解决这个问题,那么你就更有可能得到有用的答案。