javascript JSON.parse 在 Google Chrome 中失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9158665/
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
JSON.parse fails in Google Chrome
提问by theJava
var origtext = Aes.Ctr.decrypt(recentPatientsFile.read().text, 'L0ck it up saf3', 256);
var recentPatientsList = JSON.parse(origtext);
while doing an alert(origtext)
, i get empty data. The JSON.parse(empty data) works fine in other browsers, but in google chrome i get Uncaught SyntaxError: Unexpected end of input
. When i remove the JSON.parse(), then everything seems to be fine.
在做一个时alert(origtext)
,我得到空数据。JSON.parse(empty data) 在其他浏览器中工作正常,但在谷歌浏览器中我得到Uncaught SyntaxError: Unexpected end of input
. 当我删除 JSON.parse() 时,一切似乎都很好。
回答by Oybek
Just escape it like this
就这样逃避
var value = JSON.parse(origtext || "null");