Html5文件读取器-读取本地Json数组文件并仅显示特定部分
Html5 filereader - read local Json Array file and display only a specific section
我是一个初学者,来自VBA excel编程工具。在VBA中读取excel文件、操作excel内容比使用Filereader和Json数组等web工具要容易得多。
我在Json数组文件中有以下内容。
[
["TWE",6000,4545.5 ],
["RW",1000,256.3 ]
]
我想从下面的html文件中读取,并只显示值253.6
你能帮我吗?
这里的Html文件读取器示例
<!DOCTYPE html>
<html>
<head>
<script>
function handleFileSelect()
{
if (window.File && window.FileReader && window.FileList && window.Blob) {
} else {
alert('The File APIs are not fully supported in this browser.');
return;
}
input = document.getElementById('fileinput');
if (!input) {
alert("Um, couldn't find the fileinput element.");
}
else if (!input.files) {
alert("This browser doesn't seem to support the `files` property of file inputs.");
}
else if (!input.files[0]) {
alert("Please select a file before clicking 'Load'");
}
else {
file = input.files[0];
fr = new FileReader();
fr.onload = receivedText;
fr.readAsText(file);
}
}
function receivedText() {
//result = fr.result;
document.getElementById('editor').appendChild(document.createTextNode(fr.result))
}
</script>
</head>
<body>
<input type="file" id="fileinput"/>
<input type='button' id='btnLoad' value='Load' onclick='handleFileSelect();'>
<div id="editor"></div>
</body>
</html>
如果将fr.readAsText中的文本转换为字符串,则可以使用JSON.parse()(请参阅:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)将字符串转换为JSON对象。然后,您可以像访问普通数组一样访问您的特定内容。
相关文章:
- Javascript:检测文件读取器中是否有图像
- 从多个文件中推送文本的函数(使用html5文件读取器上传)返回数组
- 从d3.js中的文件读取json数据不起作用
- Javascript文件读取器
- 从外部javascript文件读取var并将其转换为php变量
- 在jQuery/JS中将文件读取为字符串
- Chrome应用程序:从服务器上的文件读取和写入数据
- 文件读取器无法在chrome和IE中工作
- 将节点.js对象设置为从文件读取的数据
- Django从通过网站上传的文件读取
- 在文件读取器中追加的订单问题
- 从 JavaScript 中的本地 JSON 文件读取时出错
- 是否有可能使用三个.js文件读取STEP文件
- 将文件读取到 blob 并以 JavaScript 格式显示
- 文件读取器和 Blob 的关闭编译器警告 - 无法修复它
- 使用 knex 从文件读取并插入数据库结束错误
- Corodva 文件读取执行成功和失败回调
- 文件读取器 JS 抛出对象正忙于读取 blob
- 承诺在 NodeJS 中循环和文件读取
- 无法弄清楚 $.get 上的回调以将文本文件读取到数组中