webgui/www/extras/yui/docs/YAHOO.lang.JSON.html
2008-03-25 16:13:25 +00:00

669 lines
32 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>API: json YAHOO.lang.JSON (YUI Library)</title>
<link rel="stylesheet" type="text/css" href="assets/api.css">
<script type="text/javascript" src="assets/api-js"></script>
<script type="text/javascript" src="assets/ac-js"></script>
</head>
<body id="yahoo-com">
<div id="doc3" class="yui-t2">
<div id="hd">
<a href="http://developer.yahoo.com/yui/"><h1>Yahoo! UI Library</h1></a>
<h3>json&nbsp; <span class="subtitle">2.5.1</span></h3>
<p>
<a href="./index.html">Yahoo! UI Library</a>
&gt; <a href="./module_json.html">json</a>
&gt; YAHOO.lang.JSON
</p>
</div>
<div id="bd">
<div id="yui-main">
<div class="yui-b">
<form name="yui-classopts-form">
<span id="classopts"><input type="checkbox" name="showprivate" id="showprivate" /> Show Private</span>
<span id="classopts"><input type="checkbox" name="showprotected" id="showprotected" /> Show Protected</span>
</form>
<h2>
<code>static</code>
Class <b>YAHOO.lang.JSON</b>
<span class="extends">
</span>
<span class="extends">
</span>
</code>
</h2>
<!-- class tree goes here -->
<div class="summary description">
Provides methods to parse JSON strings and convert objects to JSON strings.
</div>
<div class="section field details">
<h3 id="properties">Properties</h3>
<div class="content">
<div class="private">
<h4><a name="property__BRACKETS">_BRACKETS</a>
<code>- private static {RegExp}</code>
</h4>
<div class="detail">
<div class="description">
Third step in the validation. Regex used to remove all open square
brackets following a colon, comma, or at the beginning of the string.
</div>
</div>
<hr />
</div>
<div class="private">
<h4><a name="property__CHARS">_CHARS</a>
<code>- private static {Object}</code>
</h4>
<div class="detail">
<div class="description">
Character substitution map for common escapes and special characters.
</div>
</div>
<hr />
</div>
<div class="private">
<h4><a name="property__ESCAPES">_ESCAPES</a>
<code>- private static {RegExp}</code>
</h4>
<div class="detail">
<div class="description">
First step in the validation. Regex used to replace all escape
sequences (i.e. "\\", etc) with '@' characters (a non-JSON character).
</div>
</div>
<hr />
</div>
<div class="private">
<h4><a name="property__INVALID">_INVALID</a>
<code>- private static {RegExp}</code>
</h4>
<div class="detail">
<div class="description">
Final step in the validation. Regex used to test the string left after
all previous replacements for invalid characters.
</div>
</div>
<hr />
</div>
<div class="private">
<h4><a name="property__PARSE_DATE">_PARSE_DATE</a>
<code>- private static {RegExp}</code>
</h4>
<div class="detail">
<div class="description">
Regex used to reconstitute serialized Dates.
</div>
</div>
<hr />
</div>
<div class="private">
<h4><a name="property__SPECIAL_CHARS">_SPECIAL_CHARS</a>
<code>- private static {RegExp}</code>
</h4>
<div class="detail">
<div class="description">
Regex used to replace special characters in strings for JSON
stringification.
</div>
</div>
<hr />
</div>
<div class="private">
<h4><a name="property__VALUES">_VALUES</a>
<code>- private static {RegExp}</code>
</h4>
<div class="detail">
<div class="description">
Second step in the validation. Regex used to replace all simple
values with ']' characters.
</div>
</div>
<hr />
</div>
</div>
</div>
<div class="section method details">
<h3 id="methods">Methods</h3>
<div class="content">
<div class="private">
<h4>
<a name="method__applyFilter">_applyFilter</a></h4>
<div class="detail">
<code>
private
static
MIXED
<strong>_applyFilter</strong>
(
data
,
filter
)
</code>
<div class="description">
Traverses nested objects, applying a filter or mutation function to
each value. The value returned from the function will replace the
original value in the key:value pair. If the value returned is
undefined, the key will be omitted from the returned object.
</div>
<div class="description">
<dl>
<dt>Parameters:</dt>
<dd>
<code>data &lt;MIXED&gt;</code>
Any JavaScript data
</dd>
<dd>
<code>filter &lt;Function&gt;</code>
filter or mutation function
</dd>
</dl>
<dl>
<dt>Returns:
<code>
MIXED
</code></dt>
<dd>The results of the filtered data</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="">
<h4>
<a name="method_dateToString">dateToString</a></h4>
<div class="detail">
<code>
static
String
<strong>dateToString</strong>
(
d
)
</code>
<div class="description">
Serializes a Date instance as a UTC date string. Used internally by
stringify. Override this method if you need Dates serialized in a
different format.
</div>
<div class="description">
<dl>
<dt>Parameters:</dt>
<dd>
<code>d &lt;Date&gt;</code>
The Date to serialize
</dd>
</dl>
<dl>
<dt>Returns:
<code>
String
</code></dt>
<dd>stringified Date in UTC format YYYY-MM-DDTHH:mm:SSZ</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="">
<h4>
<a name="method_isValid">isValid</a></h4>
<div class="detail">
<code>
static
boolean
<strong>isValid</strong>
(
str
)
</code>
<div class="description">
Four step determination whether a string is valid JSON. In three steps,
escape sequences, safe values, and properly placed open square brackets
are replaced with placeholders or removed. Then in the final step, the
result of all these replacements is checked for invalid characters.
</div>
<div class="description">
<dl>
<dt>Parameters:</dt>
<dd>
<code>str &lt;String&gt;</code>
JSON string to be tested
</dd>
</dl>
<dl>
<dt>Returns:
<code>
boolean
</code></dt>
<dd>is the string safe for eval?</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="">
<h4>
<a name="method_parse">parse</a></h4>
<div class="detail">
<code>
static
MIXED
<strong>parse</strong>
(
s
,
filter
)
</code>
<div class="description">
Parse a JSON string, returning the native JavaScript representation.
Only minor modifications from http://www.json.org/json.js.
</div>
<div class="description">
<dl>
<dt>Parameters:</dt>
<dd>
<code>s &lt;string&gt;</code>
JSON string data
</dd>
<dd>
<code>filter &lt;function&gt;</code>
(optional) function(k,v) passed each key value pair of object literals, allowing pruning or altering values
</dd>
</dl>
<dl>
<dt>Returns:
<code>
MIXED
</code></dt>
<dd>the native JavaScript representation of the JSON string</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="">
<h4>
<a name="method_stringify">stringify</a></h4>
<div class="detail">
<code>
static
string
<strong>stringify</strong>
(
o
,
w
,
d
)
</code>
<div class="description">
Converts an arbitrary value to a JSON string representation.
Cyclical object or array references are replaced with null.
If a whitelist is provided, only matching object keys will be included.
If a depth limit is provided, objects and arrays at that depth will
be stringified as empty.
</div>
<div class="description">
<dl>
<dt>Parameters:</dt>
<dd>
<code>o &lt;MIXED&gt;</code>
any arbitrary object to convert to JSON string
</dd>
<dd>
<code>w &lt;Array&gt;</code>
(optional) whitelist of acceptable object keys to include
</dd>
<dd>
<code>d &lt;number&gt;</code>
(optional) depth limit to recurse objects/arrays (practical minimum 1)
</dd>
</dl>
<dl>
<dt>Returns:
<code>
string
</code></dt>
<dd>JSON string representation of the input</dd>
</dl>
</div>
</div>
<hr />
</div>
<div class="">
<h4>
<a name="method_stringToDate">stringToDate</a></h4>
<div class="detail">
<code>
Date
<strong>stringToDate</strong>
(
str
)
</code>
<div class="description">
Reconstitute Date instances from the default JSON UTC serialization.
Reference this from a parse filter function to rebuild Dates during the
parse operation.
</div>
<div class="description">
<dl>
<dt>Parameters:</dt>
<dd>
<code>str &lt;String&gt;</code>
String serialization of a Date
</dd>
</dl>
<dl>
<dt>Returns:
<code>
Date
</code></dt>
<dd></dd>
</dl>
</div>
</div>
<hr />
</div>
</div>
</div>
</div>
</div>
<div class="yui-b">
<div class="nav">
<div class="module">
<h4>Modules</h4>
<ul class="content">
<li class=""><a href="module_animation.html">animation</a></li>
<li class=""><a href="module_autocomplete.html">autocomplete</a></li>
<li class=""><a href="module_button.html">button</a></li>
<li class=""><a href="module_calendar.html">calendar</a></li>
<li class=""><a href="module_charts.html">charts</a></li>
<li class=""><a href="module_colorpicker.html">colorpicker</a></li>
<li class=""><a href="module_connection.html">connection</a></li>
<li class=""><a href="module_container.html">container</a></li>
<li class=""><a href="module_cookie.html">cookie</a></li>
<li class=""><a href="module_datasource.html">datasource</a></li>
<li class=""><a href="module_datatable.html">datatable</a></li>
<li class=""><a href="module_dom.html">dom</a></li>
<li class=""><a href="module_dragdrop.html">dragdrop</a></li>
<li class=""><a href="module_editor.html">editor</a></li>
<li class=""><a href="module_element.html">element</a></li>
<li class=""><a href="module_event.html">event</a></li>
<li class=""><a href="module_get.html">get</a></li>
<li class=""><a href="module_history.html">history</a></li>
<li class=""><a href="module_imagecropper.html">imagecropper</a></li>
<li class=""><a href="module_imageloader.html">imageloader</a></li>
<li class="selected"><a href="module_json.html">json</a></li>
<li class=""><a href="module_layout.html">layout</a></li>
<li class=""><a href="module_logger.html">logger</a></li>
<li class=""><a href="module_menu.html">menu</a></li>
<li class=""><a href="module_profiler.html">profiler</a></li>
<li class=""><a href="module_profilerviewer.html">profilerviewer</a></li>
<li class=""><a href="module_resize.html">resize</a></li>
<li class=""><a href="module_selector.html">selector</a></li>
<li class=""><a href="module_slider.html">slider</a></li>
<li class=""><a href="module_tabview.html">tabview</a></li>
<li class=""><a href="module_treeview.html">treeview</a></li>
<li class=""><a href="module_uploader.html">uploader</a></li>
<li class=""><a href="module_yahoo.html">yahoo</a></li>
<li class=""><a href="module_yuiloader.html">yuiloader</a></li>
<li class=""><a href="module_yuitest.html">yuitest</a></li>
</ul>
</div>
<div class="module">
<h4>Classes</h4>
<ul class="content">
<li class="selected"><a href="YAHOO.lang.JSON.html">YAHOO.lang.JSON</a></li>
</ul>
</div>
<div class="module">
<h4>Files</h4>
<ul class="content">
<li class=""><a href="JSON.js.html">JSON.js</a></li>
</ul>
</div>
<div class="module">
<h4>Properties</h4>
<ul class="content">
<li class="private"><a href="#property__BRACKETS">_BRACKETS</a>
<!--<code>&lt;{RegExp}&gt;</code>-->
</li>
<li class="private"><a href="#property__CHARS">_CHARS</a>
<!--<code>&lt;{RegExp}&gt;</code>-->
</li>
<li class="private"><a href="#property__ESCAPES">_ESCAPES</a>
<!--<code>&lt;{RegExp}&gt;</code>-->
</li>
<li class="private"><a href="#property__INVALID">_INVALID</a>
<!--<code>&lt;{RegExp}&gt;</code>-->
</li>
<li class="private"><a href="#property__PARSE_DATE">_PARSE_DATE</a>
<!--<code>&lt;{RegExp}&gt;</code>-->
</li>
<li class="private"><a href="#property__SPECIAL_CHARS">_SPECIAL_CHARS</a>
<!--<code>&lt;{RegExp}&gt;</code>-->
</li>
<li class="private"><a href="#property__VALUES">_VALUES</a>
<!--<code>&lt;{RegExp}&gt;</code>-->
</li>
</ul>
</div>
<div class="module">
<h4>Methods</h4>
<ul class="content">
<li class="private"><!--<code>MIXED</code>-->
<a href="#method__applyFilter">_applyFilter</a>
</li>
<li class=""><!--<code>String</code>-->
<a href="#method_dateToString">dateToString</a>
</li>
<li class=""><!--<code>boolean</code>-->
<a href="#method_isValid">isValid</a>
</li>
<li class=""><!--<code>MIXED</code>-->
<a href="#method_parse">parse</a>
</li>
<li class=""><!--<code>string</code>-->
<a href="#method_stringify">stringify</a>
</li>
<li class=""><!--<code>Date</code>-->
<a href="#method_stringToDate">stringToDate</a>
</li>
</ul>
</div>
</div>
</div>
</div>
<div id="ft">
<hr />
Copyright &copy; 2007 Yahoo! Inc. All rights reserved.
</div>
</div>
</body>
</html>