title: Cordova - How to save and read JSON object from localstorage
body: <p>I have a cordova project which makes a web service call. This results in a json object</p>
  
  <pre><code>Object {deletedIds: Array[0], ... etc etc
  </code></pre>
  
  <p>I am trying to save this to a database and then read the data if there is no internet connection present.</p>
  
  <p>From the function that gets the data, I set the data into localStorage (<code>localStorage.setItem("folderData", data);</code>), then call <code>db.transaction(queryFolderTable, errorCB);</code>. </p>
  
  <p>This then reads the localstorage, saves it (if possible) and reads it (if there is no internet connection)</p>
  
  <p>When i come to select the data from the table, I call the querySuccessFolderData function</p>
  
  <pre><code>function querySuccessFolderData(tx, results) {
      var len = results.rows.length;
      alert("folderData table: " + len + " rows found.");
      for (var i=0; i&lt;len; i++){
          var folderData = results.rows.item(i).folderData;
      }
      console.log(folderData);
  }
  </code></pre>
  
  <p>When I console.log the folderData (or don't add JSON.parse to anything) I get the following:</p>
  
  <pre><code>[object Object]
  </code></pre>
  
  <p>How would I be able to successfully save the data as a json object, then read it out correctly? I have tried to JSON.parse the data before setting it in localStorage but I get the following console error</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token o 
  </code></pre>
  
  <p>If i try to JSON.parse the data when I read it from localStorage I get the following 2 errors</p>
  
  <pre><code>Uncaught SyntaxError: Unexpected token o connection.js:
  Error processing SQL: 0
  </code></pre>
  
  <p>What am i doing wrong? Do I need to JSON.stringify the data to make it readable at any point? Any help would be greatly appreciated!</p>