Html5 filereader-чтение локального файла массива Json и отображение только определенного раздела
Я новичок и пришел форма VBA excel инструмент программирования. Чтение файла excel, манипулирование содержимым excel намного проще в VBA, чем веб-инструмент, такой как Filereader и JSON array.
у меня есть следующее содержимое в моем файле массива 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>
            1 ответов
Если вы получите текст с fr.readAsText в строку, вы можете использовать JSON.parse () (см.: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) для преобразования строки в объект JSON. Затем вы можете получить доступ к конкретному контенту, как к обычному массиву.