Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (24 sloc) 578 Bytes
<!doctype html>
<html lang="en">
<head>
<title>JavaScript Patterns</title>
<meta charset="utf-8">
</head>
<body>
<script>
/* Title: Working with JSON
* Description: use library from JSON.org or YUI, jQuery library
*/
// an input JSON string
var jstr = '{"mykey": "my value"}';
// antipattern
var data = eval('(' + jstr + ')');
// preferred
// JSON.org library
var data = JSON.parse(jstr);
console.log(data.mykey); // "my value"
// References
// http://shop.oreilly.com/product/9780596806767.do
</script>
</body>
</html>