Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.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 从sqlite数据库文件以表格格式显示json结果_Javascript_Json_Html_Sqlite - Fatal编程技术网

Javascript 从sqlite数据库文件以表格格式显示json结果

Javascript 从sqlite数据库文件以表格格式显示json结果,javascript,json,html,sqlite,Javascript,Json,Html,Sqlite,我想显示mysqlite数据库文件中的数据。这是我的代码: <!DOCTYPE html> <html> <head> <title>My App</title> <script src="sql.js"></script> </head> <body> <h1>My App</h1> <div id="res" style="width:

我想显示mysqlite数据库文件中的数据。这是我的代码:

<!DOCTYPE html>
<html>
<head>
    <title>My App</title>
    <script src="sql.js"></script>

</head>
<body>
<h1>My App</h1>
<div id="res" style="width: 100%">
</div>
<script>
    function loadBinaryFile(path,success) {
        var xhr = new XMLHttpRequest();
        xhr.open("GET", path, true); 
        xhr.responseType = "arraybuffer";
        xhr.onload = function() {
            var data = new Uint8Array(xhr.response);
            var arr = new Array();
            for(var i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
            success(arr.join(""));
        };
        xhr.send();
    };


    loadBinaryFile('MyData.db', function(data){
        var db = new SQL.Database(data);

        var res = db.exec("SELECT * FROM MyRecord");
      // document.getElementById("demo").textContent = JSON.stringify(res);
        var data=JSON.stringify(res);
      document.getElementById("res").textContent=data;


});

</script>
</body>
</html>
现在,我如何以表格格式显示这些json数据。有人能帮我吗?

var数据=[{“列”:[“id”、“name”、“gender”、“fname”]、“value”:[[1”、“divya”、“female”、“rao”]、[3”、“nithin”、“male”、“kumar”]}];
数据=数据[0];
var html='';
data.columns.forEach(d=>{
html+=''+d+''
});
html+='';
data.values.forEach(行=>{
html+='';
row.forEach(项目=>{
html+=''+项目+''
});
html+='';
});

document.body.innerHTML=html当我添加这段代码时,我得到了类似“无法读取未定义的属性'forEach'”的错误,并且我使用了var db=new SQL.Database(data);在我的代码中,我使用数据作为变量名。您可以将其重命名为jsonData。上面发布的代码将上面指定的json格式转换为html表语法;我得到了那个错误。如果我按照您指定的方式硬编码json数据,我将获得输出。如果我使用JSON.stringify(res),得到错误,而不是stringify响应。只需使用res而不是代码段中的数据。如果res的格式为
[{“列”:[“id”、“name”、“gender”、“fname”]、“values]:[[1,“divya”、“female”、“rao”]、[3,“nithin”、“male”、“kumar”]}]
[{"columns":["id","name","gender","fname"],"values":[[1,"divya","female","rao"],[3,"nithin","male","kumar"]]}]