我們試圖JSON
數據插入到SqlLit
。我們需要JSON
數據插入到SqlLit
。所以我們首先箱表,然後試圖插入JSON
VALU表,但它不是work.So請告訴我什麼錯在我的代碼如何將JSON數據到sqlite的DB中的PhoneGap
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();
});
}
對於插入: -
function insert(){
alert("5");
var output = $('#output').text('Refreshing documentation...');
//$("#docs").html("Refreshing documentation...");
$.ajax({
url: 'http://headers.jsontest.com/',
type: 'GET',
contentType: "application/json;charset=utf-8",
success: function (data) {
alert("6");
// iterate over data and save it to DB
output.empty();
$.each(data, function(i,item){
alert("7");
tx.executeSql('INSERT INTO docs (id, language, cookie, host ,control) VALUES(' + item.id + ', "' + item.Accept-Language + '", "' + item.Cookie + '", "' + item.Host + '", "' + item.Cache-Control+'")');
});
output.append(landmark);
});
},
error: function (x, y, z) {
alert(x.responseText);
}
});
}
my json :--
{
"Accept-Language": "en-US,en;q=0.8",
"Cookie": "__hbblk_headersjsontestcom=0",
"Host": "headers.jsontest.com",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36",
"Via": "1.1 FFTMG",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Cache-Control": "max-age=0"
}
在我的代碼表創建成功
而是試圖將數據插入到表時它不工作。所以,請給我任何小實例用於將JSON數據插入到SqlLit DB中。
解析,並將它推爲對象,而retriving使用字符串化 – 2014-11-24 12:10:31
@MohammedImranN請你當JSON數據插入到數據庫SqlLit這 – 2014-11-24 12:12:32