YUI Library Examples: JSON Utility (beta): JSON with Connection Manager

JSON Utility (beta): JSON with Connection Manager

A natural fit for the JSON Utility is working with the Connection Manager. In this example, we'll request JSON data from the server using Connection Manager's asyncRequest and parse the resulting JSON string data for processing.

Click the Get Messages button to send the request to the server.

Include the JSON Utility

The JSON utility is an extension of YAHOO.lang. Load the JSON Utility by including these tags:

Use YAHOO.lang.JSON.parse in the success handler

Pass the XHR responseText to YAHOO.lang.JSON.parse and capture the return value. Note that the parse method can throw a SyntaxError exception, so be sure to wrap the call in a try/catch block.

The parse method returns the native JavaScript object representation of the string data returned from the asyncRequest. In this case, the data is an array of object literals in this form:

YUI Logger Output:

JSON Utility (beta) Examples:

More JSON Utility (beta) Resources:

Copyright © 2007 Yahoo! Inc. All rights reserved.

Privacy Policy - Terms of Service - Copyright Policy - Job Openings