Single vs. Double Quotes in jQuery.parseJSON
In JavaScript, the jQuery.parseJSON method converts a JSON str. When working with JSON strings, it's crucial to understand the difference between using single and double quotes.
The Issue
The Issue
var obj1 = jQuery.parseJSON('{"orderedList": "true"}');
var obj2 = jQuery.parseJSON("{'orderedList': 'true'}");
The Reason
The discreation orhing double quotes in JSON syntax. According to the JSON standard, double quotes are considered the standard for string delimiters, while single quotes are not.JSON Syntax
A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.
值得注意的是,類似的問題曾在 jQuery 社群的討論中出現過,即在 JSON 回應中使用單引號。解決這個問題的一種方法是確保在 JSON 字串中始終使用雙引號。
以上是為什麼雙引號和單引號在 jQuery.parseJSON 中的行為不同?的詳細內容。更多資訊請關注PHP中文網其他相關文章!