Note that there are some explanatory texts on larger screens.

plurals
  1. POunable to parse json data that includes a single quote
    primarykey
    data
    text
    <p><strong>Problem</strong></p> <p>I'm getting a parse error on some of my json data, because it includes single quotes. For example, some of my data could look like this: </p> <p>"Larry's data"</p> <p>I've read the following article: <a href="https://stackoverflow.com/questions/2275359/jquery-single-quote-in-json-response">jQuery single quote in JSON response</a></p> <p>and I've been trying to implement some of the solutions but I haven't been able to get rid of my parse error. </p> <p><strong>Code</strong></p> <p>In my model, I'm using a lua library to encode my data as json. The model returns data that looks like this: </p> <pre><code>[{\"createddatetime\":\"2013-09-10 17:56:55\",\"description\":\"John Doe\'s phone\",\"number\":\"72051\",\"createdname\":\"conversion script\",\"user\":\"23123\",\"position\":\"46\",\"id\":\"49\",\"user_id\":\"822\",\"password\":\"rwer234\"}]" </code></pre> <p>In my view, my code currently looks like this: </p> <pre><code> $.ajax({ url:myurl + '?startpos=' + page_index * items_per_page + '&amp;numberofrecordstograb=' + items_per_page + '&amp;viewtype=json', success: function(data){ console.log('inside'); for(var i=0;i&lt;data.length;i++) { var deviceobj = data[i]; newcontent = newcontent + "&lt;TR&gt;"; newcontent=newcontent + '&lt;TD&gt;'; //add EDIT hyperlink if ($("#editdevicesettings").val() == "true") { var temp = $("#editlinkpath").val(); newcontent=newcontent + temp.replace("xxx",deviceobj["device_id"]) + '&amp;nbsp;&amp;nbsp;'; } //add DELETE hyperlink if ($("#deletedevice").val() == "true") { var temp = $("#deletelinkpath").val(); newcontent=newcontent + temp.replace("xxx",deviceobj["device_id"]); } newcontent=newcontent + '&lt;/TD&gt;'; newcontent=newcontent + '&lt;TD&gt;' + deviceobj["number"] +'&lt;/TD&gt;'; newcontent=newcontent + '&lt;&lt;TD&gt;' + deviceobj["user"] + '&lt;/TD&gt;'; newcontent=newcontent + '&lt;&lt;TD&gt;' + deviceobj["password"] + '&lt;/TD&gt;'; if (deviceobj["name"]) { newcontent=newcontent + '&lt;TD&gt;' + deviceobj["name"] + '&lt;/TD&gt;'; } else { newcontent=newcontent + '&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;'; } newcontent=newcontent + '&lt;TD&gt;' + unescape(deviceobj["description"]) + '&lt;/TD&gt;'; newcontent = newcontent + "&lt;/TR&gt;"; }// end for // Replace old content with new content $('#Searchresult').html(newcontent); }//end if }, error: function(request, textStatus, errorThrown) { console.log(textStatus); console.log('========'); console.log(request); }, complete: function(request, textStatus) { //for additional info //alert(request.responseText); console.log(textStatus); } }); </code></pre> <p>But I still get the parse error on this particular record. </p> <p>Any suggestions would be appreciated. Thanks. </p> <p><strong>EDIT 1</strong></p> <p>I've changed my logic so that when it fails, it print out "request.responseText" into the console. Here's what it looks like: </p> <pre><code>"[{\"createddatetime\":\"2013-09-10 17:56:55\",\"description\":\"John Doe\'s phone\",\"number\":\"72051\",\"createdname\":\"conversion script\",\"user\":\"28567\",\"position\":\"46\",\"id\":\"49\",\"user_id\":\"822\",\"password\":\"rwer234\"}]" </code></pre> <p>The apostrophe is still escaped.</p> <p><strong>EDIT 2</strong></p> <p>Here's what my code looks like on the server side (aka. in the model): </p> <pre><code>get_device_records = function(ajaxdata) local results = list_devices(nil,false,ajaxdata.startpos, ajaxdata.numberofrecordstograb) return results.value end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload