parse()
JSON
class method
JS Home <<
JS Reference <<
JSON <<
parse()
Description
Returns a parsed JSON string.
- Like all class methods
parse()
should be used on the class rather than an instance of the class.
Syntax
Signature | Description |
---|---|
JSON.parse(someText[, transformer]) | Returns a parsed JSON string. |
Parameters
Parameter | Description |
---|---|
someText | The value you wish to parse to JSON format. |
transformer | Computed value transformed prior to return. |
Examples
// Store properties in an array.
var parseMethod = new Array(10);
parseMethod[0] = 'Parse some data: ';
parseMethod[1] = JSON.parse('""'); // Empty String
parseMethod[2] = JSON.parse('"A string"'); // A String
parseMethod[3] = JSON.parse('[1, 2, 3, 4]'); // Single type array
parseMethod[4] = JSON.parse('[1, "2", 3, "true"]'); // Multi type array
parseMethod[5] = JSON.parse('null'); // null
parseMethod[6] = 'Parse a function with arguments: ';
parseMethod[7] = JSON.parse('{"Square": 3}',
function(a, b) { if (a === "")
return b; return b * b; }); // func
parseMethod[8] = 'Stringify parsed function: ';
parseMethod[9] = JSON.stringify(parseMethod[7]); // value of func
alert(parseMethod);
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 7 - Object Literals