猿问

解析JSON时出现“意外令牌o”错误

我在解析简单的JSON字符串时遇到问题。我已经在JSONLint上检查了它们,并显示它们是有效的。但是,当我尝试使用JSON.parsejQuery替代方法解析它们时,出现了以下错误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>

注意:我json_encode()在PHP中使用字符串编码。



GCT1015
浏览 300回答 3
3回答

小怪兽爱吃肉

您的数据已经是一个对象。无需解析。javascript解释器已经为您解析了它。var cur_ques_details ={"ques_id":15,"ques_title":"jlkjlkjlkjljl"};document.write(cur_ques_details['ques_title']);

九州编程

尝试解析如下:var yourval = jQuery.parseJSON(JSON.stringify(data));

回首忆惘然

使用JSON.stringify(data);:$.ajax({&nbsp; &nbsp; url: ...&nbsp; &nbsp; success:function(data){&nbsp; &nbsp; &nbsp; &nbsp; JSON.stringify(data); //to string&nbsp; &nbsp; &nbsp; &nbsp; alert(data.you_value); //to view you pop up&nbsp; &nbsp; }});
随时随地看视频慕课网APP

相关分类

Java
我要回答