|
1 | 1 | <?xml version="1.0"?>
|
2 |
| -<entry type="method" name="jQuery.parseJSON" return="Object"> |
| 2 | +<entry type="method" name="jQuery.parseJSON"> |
| 3 | + <return type="String"/> |
| 4 | + <return type="Number"/> |
| 5 | + <return type="Object"/> |
| 6 | + <return type="Array"/> |
| 7 | + <return type="Boolean"/> |
3 | 8 | <title>jQuery.parseJSON()</title>
|
4 | 9 | <signature>
|
5 | 10 | <added>1.4.1</added>
|
6 | 11 | <argument name="json" type="String">
|
7 | 12 | <desc>The JSON string to parse.</desc>
|
8 | 13 | </argument>
|
9 | 14 | </signature>
|
10 |
| - <desc>Takes a well-formed JSON string and returns the resulting JavaScript object.</desc> |
| 15 | + <desc>Takes a well-formed JSON string and returns the resulting JavaScript value.</desc> |
11 | 16 | <longdesc>
|
12 |
| - <p>Passing in a malformed JSON string results in a JavaScript exception being thrown. For example, the following are all malformed JSON strings:</p> |
| 17 | + <p>Passing in a malformed JSON string results in a JavaScript exception being thrown. For example, the following are all invalid JSON strings:</p> |
13 | 18 | <ul>
|
14 |
| - <li><code>{test: 1}</code> (test does not have double quotes around it).</li> |
15 |
| - <li><code>{'test': 1}</code> ('test' is using single quotes instead of double quotes).</li> |
| 19 | + <li><code>"{test: 1}"</code> (test does not have double quotes around it).</li> |
| 20 | + <li><code>"{'test': 1}"</code> ('test' is using single quotes instead of double quotes).</li> |
| 21 | + <li><code>"'test'"</code> ('test' is using single quotes instead of double quotes).</li> |
| 22 | + <li><code>".1"</code> (a numbers must start with a digit; <code>"0.1"</code> would be valid).</li> |
| 23 | + <li><code>"undefined"</code> (<code>undefined</code> cannot be represented in a JSON string; <code>null</code>, however, can be).</li> |
| 24 | + <li><code>"NaN"</code> (<code>NaN</code> cannot be represented in a JSON string; direct representation of <code>Infinity</code> is also not permitted).</li> |
16 | 25 | </ul>
|
17 | 26 | <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>
|
18 | 27 | <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>
|
19 |
| - <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> |
| 28 | + <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> |
20 | 29 | </longdesc>
|
21 | 30 | <example>
|
22 | 31 | <desc>Parse a JSON string.</desc>
|
|
0 commit comments