I am having some trouble getting json to load into a sqlite database.
The database and tables get created on the app before I make AJAX calls to my webservice.
The web service is returning json data and I am trying to load a sqlite table with this code:
function LoadContractsToSQLite() {
var json = GetContractData();
var j = $.parseJSON(json);
for (var key in j) {
if(json.hasOwnProperty(key)) {
id = j[key].id;
alert(id);
contractname = j[key].contract_name;
alert(contractname);
isactive = j[key].is_active;
}
args = [id, contractname, isactive];
var s = new Array(["INSERT OR REPLACE INTO contract (id, contract_name, is_active) VALUES (?,?,?);", args]);
Sql(DB, s);
}
}
Uncaught SyntaxError: Unexpected token u in JSON at position 0
at Function.parse [as parseJSON] ()
at LoadContractsToSQLite (code.js:386)
at yesNoDownload (code.js:27)
at Dialog.buttonObj. (appstudioFunctions.js:1459)
at HTMLButtonElement. (appstudioFunctions.js:1841)
I was not getting the right format from the Web API get function I wrote in C#.
If anyone is interested, this is the Web API action:
[HttpGet]
[Route("api/mobile/GetContractsList")]
public IHttpActionResult GetContractsList()
{
var contracts = from c in db.Contracts
select new { c.id, c.contract_name, c.is_active};
return Ok(contracts.ToList());
}