javascript 无法解析 JSON,未捕获的语法错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6458175/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to parse JSON, uncaught syntax error?
提问by Preethi
I am trying to parse the following JSON:
我正在尝试解析以下 JSON:
06-22 18:49:17.182: ERROR/HTMLContacts(2716): Json:
[{"contactId":"1","contactPhoto":"SIkADAjz94lQTkcNChoKAAAADUlIRFIAAABgAAAAYAgCAAAAbfrgbwAAAANzQklUBQYFMwuNgAAA\nHuhJREFUeJztfU2LJLuS5ZlGAcfAEyTIggy4D14uZjGznB87q9nO75nFwMyiG+rBuxAJN0GCdLAD\nocUsTHL3yMisj3vvm6abFkVVVoRcLpns85hJ+Z/+53//Hw4g4djUoS50oEsdANwF+PnLmaQ60IEE... }
It is a huge string array with an array length of almost 10,000.
它是一个巨大的字符串数组,数组长度接近 10,000。
I get the following error message:
我收到以下错误消息:
Uncaught SyntaxError: Unexpected token ILLEGAL -- From line 1 of file:///android_asset/www/index.html
Could someone explain what is happening?
有人可以解释发生了什么吗?
回答by thescientist
I can't make any sense of that at all. Have you tried validating your JSON first though? http://jsonlint.com/
我完全无法理解。您是否尝试过先验证您的 JSON? http://jsonlint.com/
回答by user2547151
I had the same problem with my phoneGap app running on MC40 android 2.3 and all I had to do is replace JSON.parse with $.parseJSON
.Apparently JSON.parse has compatibility issues with older browsers.
我的 phoneGap 应用程序在 MC40 android 2.3 上运行时遇到了同样的问题,我所要做的就是替换。JSON.parse with $.parseJSON
显然 JSON.parse 与旧浏览器存在兼容性问题。
回答by TravMan
Unescaped character that JavaScript isn't liking. Make sure it can take any character you receive.
JavaScript 不喜欢的未转义字符。确保它可以接受您收到的任何字符。
回答by NotAMeme
Make sure there are no tabs in there by replacing them with \t
.
通过将它们替换为 ,确保其中没有选项卡\t
。