码迷,mamicode.com
首页 > Web开发 > 详细

jQuery解析JSON出现SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

时间:2017-06-03 17:31:23      阅读:419      评论:0      收藏:0      [点我收藏+]

标签:证明   理解   append   span   ons   status   加载   stat   json解析   

SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

我在使用$.parseJSON解析后台返回的JSON的数据时,出现了这样的错误,我还以为返回的JSON格式出现了错误,因为JSON要求格式非常严格。最后发现JSON格式没有太明显的格式错误,我使用fastJSON来生成的JSON格式数据,原来是因为数据已经是一个JavaScript对象了,所以在进行解析就会出错了

我直接将这段数据alert出来,并使用typeof检验其类型,发现是一个Object,这就证明了数据已成为了JavaScript对象了。所以,我直接使用(不用什么parseJSON解析了)这段数据进行相应的处理就不会出错

                            $.ajax({
                                url : ‘commentAction_showComment‘,
                                type : ‘POST‘,
                                data:{
                                    titleid: $(comment_this).attr(‘data-id‘),         
                                    currPage : currPage,
                                },
                                beforeSend : function (jqXHR, settings) {
                                    $(‘.comment_list‘).eq(index).append(‘<dl class="comment_load"><dd>正在加载评论</dd></dl>‘);
                                },
                                success : function (response, status) {
                                    var json_comment = response;
                                },
                            });

也许是我对jQuery的parseJSON方法理解错误使用不当,或者是该用其他的方法处理?

jQuery解析JSON出现SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

标签:证明   理解   append   span   ons   status   加载   stat   json解析   

原文地址:http://www.cnblogs.com/lz2017/p/6937499.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!