I create a shopping cart that, when I click the Buy button, the web service returns JSON output, which I then save as a Javascript file as a string.
A typical return from a web service might be:
{ "d":{ "58658":{ "id":"58658", "qty":"1", "singlePrice":"754", "salePrice":"754", "isBulk":"0", "isSor":"0", "vatRate":"20.00", "masterCat":"6", "imgUrl":"http://...img url", "singleWeight":"18000", "totalAvailableStock":"2", "thirdPartyStock":"", "item":"Electrovoice Live X Elx115p, Each " // << HERE IS THE ISSUE } } }
When the return looks like the one shown above, it will only work in Safari
After spending a lot of time trying to find some useful mechanism for debugging this without buying a Mac, I finally traced it to:
"item":"Electrovoice Live X Elx115p, Each "
The item value has a comma in the string, I save the return value to a cookie with something like:
cookies.set('shopping_cart', JSON.stringify(result));
When I try to recall this later:
var shopping_cart = cookies.get('shopping_cart'); shopping_cart = JSON.parse(shopping_cart);
It works fine in any browser, even, apparently, in Internet Explorer ... EXCEPT Safari
I donβt have a Mac, so I'm not sure if Safari on Mac is different than others, but of course the Windows version has this error and this happens on my iPhone and iPad.
Error:
JSON parse error, unterminated string.
As I said, this only seems to be a problem in Safari, but I find it difficult to find a solution.
Help rate!
EDIT:
I created a script: http://jsfiddle.net/jhartnoll/2GLEz/ This script will replicate the problem, it is associated with storing data as a string in a cookie and reanalyzing it in JSON
But since I turned on my Cookie features as an external resource ( http://www.sam.thinkka.com/clientscripts/cookie_test.js ), you will need to make sure that Safari does not block third-party cookies.