首页 > 代码库 > jQuery解析JSON出现SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
jQuery解析JSON出现SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。