为什么JSON.parse的行为与预期不符? 在这个例子中,弹出框不会被触发:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Testing JSON.parse</title>
<script type="text/javascript" src="js/json2.js">
// json2.js can be found here: https://github.com/douglascrockford/JSON-js/blob/master/json2.js
</script>
<script type="text/javascript">
function testJSONParse()
{
var text = '[{"a":"w","b","x"},{"a":"y","b":"z"}]';
alert(JSON.parse(text));
}
window.onload = testJSONParse;
</script>
</head>
<body>
</body>
</html>
在Firefox中,错误控制台显示“JSON.parse”。这并不是很描述清楚。
这是我遇到的一个问题的简化版本,该问题使用AJAX从数据库获取数据,并将结果作为与上面示例中的“text”相同形式的JSON字符串(表示JSON对象的字符串)获取。