What actually the difference between this?
This works fine:
var obj1 = jQuery.parseJSON('{"orderedList": "true"}');
document.write("obj1 "+ obj1.orderedList );
but the following does not work:
var obj2 = jQuery.parseJSON("{'orderedList': 'true'}");
document.write("obj2 "+ obj2.orderedList );
Why is that?
As per the API documentation, double quotes are considered valid JSON, single quotes aren't.
http://api.jquery.com/jQuery.parseJSON/
You could use replace to fix this. This worked for me.
That's because double quotes is considered standard while single quote is not. This is not really specific to JQuery, but its about JSON standard. So irrespective of JS toolkit, you should expect same behaviour.
Update
Or perhaps its a duplicate of jQuery single quote in JSON response
Go to www.Jsonlint.com website and check your single quotes json string you will found that it is not a valid json string. Because double quotes json is standard json format.
jsonlint.com is a website to check json format right or not.