control-freak-ide/Control-Freak-Documentation/jQuery/docs/entries/jQuery.parseJSON.json
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

1 line
1.8 KiB
JSON

{"name":"jQuery.parseJSON","type":"method","title":"jQuery.parseJSON()","deprecated":null,"removed":null,"desc":"Takes a well-formed JSON string and returns the resulting JavaScript object.","categories":["utilities","version/1.4.1"],"entries":[{"return":"Object","signatures":{"added":"1.4.1","argument":{"desc":"The JSON string to parse.","name":"json","type":"String"}},"examples":{"desc":"Parse a JSON string.","code":"\nvar obj = jQuery.parseJSON( '{ \"name\": \"John\" }' );\nalert( obj.name === \"John\" )\n;"},"longdesc":"\n <p>Passing in a malformed JSON string results in a JavaScript exception being thrown. For example, the following are all malformed JSON strings:</p>\n <ul>\n <li><code>{test: 1}</code> (test does not have double quotes around it).</li>\n <li><code>{'test': 1}</code> ('test' is using single quotes instead of double quotes).</li>\n </ul>\n <p>The JSON standard does not permit \"control characters\" such as a tab or newline. An example like <code>$.parseJSON( '{ \"testing\":\"1\\t2\\n3\" }' )</code> will throw an error in most implementations because the JavaScript parser converts the string's tab and newline escapes into literal tab and newline; doubling the backslashes like <code>\"1\\\\t2\\\\n3\"</code> yields expected results. This problem is often seen when injecting JSON into a JavaScript file from a server-side language such as PHP.</p>\n <p>Where the browser provides a native implementation of <code>JSON.parse</code>, jQuery uses it to parse the string. For details on the JSON format, see <a href=\"http://json.org/\">http://json.org/</a>.</p>\n <p>Prior to jQuery 1.9, <code>$.parseJSON</code> returned <code>null</code> instead of throwing an error if it was passed an empty string, <code>null</code>, or <code>undefined</code>, even though those are not valid JSON. </p>\n "}]}