YUI 3.x Home -

YUI Library Examples: JSON Utility: JSON with Y.io

Note: This is YUI 3.x. Looking for YUI 2.x?

JSON Utility: JSON with Y.io

A natural fit for the JSON Utility is working with the io module. In this example, we'll request JSON data from the server using the Y.io method and parse the resulting JSON string data for processing.

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

Use Y.JSON.parse in the success handler

Pass the XHR responseText to Y.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 Y.io call. In this case, the data is an array of object literals in this form:

Copyright © 2008 Yahoo! Inc. All rights reserved.

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