Skip to content Skip to sidebar Skip to footer

Unable To Parse Json Data That Includes A Single Quote

Problem 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: 'Larry's data' I've read the foll

Solution 1:

Looks like you are doing double serialisation on the server side. Happens for example if your web framework automatically serialises the returned object but you make an extra explicit, unnecessary serialise call on your object. The fact that your code works with no ' cases proves this: jquery makes one parse automatically (because of the dataType) then you run another parseJSON. That shouldn't work :) Fix your serialisation on the server side and remove the unnecessary parseJSON call from your success method. Every other solution is just a workaround not a real fix.


Solution 2:

try replacing

data = data.replace("\\'", "'");

with

data = data.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');

I had a similar problem with parsing JSON data and this code from another answer solved it


Solution 3:

This is a bug in the lua json.encode function of the json4lua 0.9.40 library. It erroneously escapes single quotes. This is corrected in 0.9.50:

https://github.com/craigmj/json4lua


Solution 4:

Just take out the \\ from the json response. I mean, pass the single quote as it is, like this:

[{\"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\"}]"

Post a Comment for "Unable To Parse Json Data That Includes A Single Quote"