【发布时间】:2013-03-15 01:45:44
【问题描述】:
我在解析简单的 JSON 字符串时遇到问题。我在JSONLint 上检查了它们,它表明它们是有效的。但是,当我尝试使用 JSON.parse 或 jQuery 替代方法解析它们时,它给了我错误 unexpected token o:
<!doctype HTML>
<html>
<head>
</head>
<body>
<script type="text/javascript">
var cur_ques_details ={"ques_id":15,"ques_title":"jlkjlkjlkjljl"};
var ques_list = JSON.parse(cur_ques_details);
document.write(ques_list['ques_title']);
</script>
</body>
</html>
注意:我在 PHP 中使用 json_encode() 对字符串进行编码。
【问题讨论】:
-
将其更改为:var ques_list = JSON.stringify(cur_ques_details);谢谢。
标签: javascript json