I am trying to store an entry with the following json String in a database. However, it seems like the format of the json string is not agreeing with the db even though I have read articles saying this should be easy:
I have tried:
function Activity() {
this.clicks = 100;
this.activityTypeCode = 3;
}
var anActivity=new Activity();
var jsonString=JSON.stringify(anActivity);
database.transaction(function(tx) {
tx.executeSQL('INSERT INTO MYTABLE(ID, DATA) VALUES (100,'+jsonString+')');
}, errorCB, successCB)
;
and I get an error that says error unrecognized token “{“.
when I do console.log(jsonString) I get:
{"clicks":100, "activityTypeCode":3}
Any assistance would be appreciated.
First is to make sure that your json string is correct. You can validate your json string here.
Second debug is you are missing a ‘;’ in your insert statement in executeSQL. The value array is missing as well.
Third debug would be your executeSQL statement. Try this:
Have you declared ID as AUTOINCREMENT? You cant assign values to an AUTOINCREMENT column.
Hope this helps.!