标签:证明 理解 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