Jquery 如何在PhoneGap中将json数据插入Sqlite数据库

Jquery 如何在PhoneGap中将json数据插入Sqlite数据库,jquery,json,sqlite,jquery-mobile,cordova,Jquery,Json,Sqlite,Jquery Mobile,Cordova,我们试图将JSON数据插入SqlLit。我们需要将JSON数据插入SqlLit。因此,首先我们将表装箱,然后尝试将JSON值插入表中,但这不起作用。所以请告诉我代码中有什么错误 function startup() { alert("1"); console.log("Starting up..."); db = window.openDatabase("Database", "1.0", "Cordova Demo",10485760); db.transactio

我们试图将
JSON
数据插入
SqlLit
。我们需要将
JSON
数据插入
SqlLit
。因此,首先我们将表装箱,然后尝试将
JSON
值插入表中,但这不起作用。所以请告诉我代码中有什么错误

function startup() {
alert("1");
    console.log("Starting up...");
      db = window.openDatabase("Database", "1.0", "Cordova Demo",10485760);
    db.transaction(function(tx){
    alert("2");
         tx.executeSql('DROP TABLE IF EXISTS HEADER_DATA');
          tx.executeSql("create table if not exists docs(id INTEGER PRIMARY KEY AUTOINCREMENT, language TEXT, cookie TEXT, host TEXT, control TEXT)");
    },function(tx,error){
    alert("3");
        console.log('tx error: ' + error);
    },function(){
    alert("4");
        console.log('tx success');
         insert();
    });
}
插入:--


在我的代码中,表创建成功,但当尝试将数据插入表中时,它不起作用。因此,请给我任何关于将JSON数据插入SqlLit DB的小示例。

从我看到的情况来看,可能错误在JSON处理程序中

尝试使用类似以下内容:

$.support.cors=true;                        // this two allow you to ask page outside ypur phone
$.mobile.allowCrossDomainPages = true;      //
$.getJSON('http://headers.jsontest.com/?callback=?',function(data){
    $.each(data, function(i, dat){
        $("#someul").append('<li>'+dat.rep+'</li>');  //i send data in json using rep as index
    });
});
$.support.cors=true;//这两个允许您在ypur电话外询问page
$.mobile.allowCrossDomainPages=true//
$.getJSON('http://headers.jsontest.com/?callback=?,函数(数据){
$。每个(数据、函数(i、dat){
$(“#someul”).append(“
  • ”+dat.rep+”
  • ”);//我使用rep作为索引发送json格式的数据 }); });
    将其作为对象进行解析和推送,并在检索时使用stringify@MohammedImranN您能详细解释一下吗?谢谢您的回复,当json数据插入SqlLit数据库时,我们面临着一个问题,所以请帮助我给出一个关于我的问题的小例子。我认为这是一个错误,定义了像“id INTEGER主键自动增量”这样的id列因为autoincrement会修改默认行为。由于您在代码集中设置了id,请尝试不使用自动增量。
    $.support.cors=true;                        // this two allow you to ask page outside ypur phone
    $.mobile.allowCrossDomainPages = true;      //
    $.getJSON('http://headers.jsontest.com/?callback=?',function(data){
        $.each(data, function(i, dat){
            $("#someul").append('<li>'+dat.rep+'</li>');  //i send data in json using rep as index
        });
    });