You need to sign in to do that
Don't have an account?
Cordova : SyntaxError: Unable to parse JSON string
Hello,
First, I'm sorry if I have a bad language.
I am trying to do the Cloud Tunes project (Mobile SDK Workbook) with objects Album__c and Track__c. I have modified to add/modify datas in Salesforce and to store offline data manually.
The problem is when I wish store an offline track manually, I use this code :
[code]
var TRACKS_SOUP_NAME = "ct__tracksSoup";
function regOfflineSoups() {
if (hasSmartstore()) {
var smartStore = cordova.require("salesforce/plugin/smartstore");
console.log("Registering soups");
//Registering soup 2 for storing tracks
var indexesTracks = [
{path:"Name",type:"string"},
{path:"Id",type:"string"},
{path:"Album__c",type:"string"}
];
smartStore.registerSoup(TRACKS_SOUP_NAME,
indexesTracks,
onSuccessRegSoup,
onErrorRegSoup);
}
function addOfflineTracks(entries, success, error) {
if (hasSmartstore()) {
var smartStore = cordova.require("salesforce/plugin/smartstore");
smartStore.upsertSoupEntries(TRACKS_SOUP_NAME,entries,
success,
error);
}
}
}
function Track(){
this.Id = null;
this.Name = null;
this.Price__c = null;
this.Album__c = null;
}
function parseJsonPerso(track){
return {"Name" : track.Name, "Id" : track.Id, "Album__c" : track.Album__c};
}
var track = new Track();
track.Name = 'name';
track.Album__c = '1234567890azert';
addOfflineTracks(new Array(parseJsonPerso(track)), sucessCallback, displayError);
[/code]
Then, I get this error:
[quote]
processMessage failed: Error: SyntaxError: Unable to parse JSON string at https://c.na15.visual.force.com/resource/1370942151000/Cordova/cordova-android.js:1091
[/quote]
What can I do to fix that please?
Thanks for your answers.
I resolved my problem.
Rather than use this function :
[code]
addOfflineTracks(new Array(parseJsonPerso(track)), sucessCallback, displayError);
[/code]
I used that :
[code]
var myTable = [];
addOfflineTracks(myTable.push(track));
[/code]