Converting a JSON text into a JavaScript object

May 20, 08 by the programmer

JSON (JavaScript Object Notation) is a data-interchange format.

It is often used with client-side JavaScript applications that make use of HTTPRequest to perform server communication functions. Most of the time it is used in conjunction with AJAX.

Data can be encoded into JSON notation for use in a client-side javascript, or decoded from incoming Javascript requests.

JSON format is native to Javascript, and can be converted to JavascriptObject directly using the eval() function.

To decode a JSON text that is passed to a JavaScript into a JavaScript Object you need to use the eval() function by passing the JSON encoded text as a parametar.

The JSON string is wrapped in parenthesis because eval is interpreting the first item in the JSON string as a JavaScript Label.

var returned_object = eval(’(’ + JSON_text + ‘)’);

This entry no have comments... but you can be first.

Leave a Reply