[英]Javascript JSON.parse: Uncaught SyntaxError: Unexpected token N
I have JSON data generated in Python using Flask's jsonify
method. 我使用Flask的
jsonify
方法在Python中生成JSON数据。
When I try to parse it in Google Chrome by doing 当我尝试在谷歌浏览器中解析它时
JSON.parse(s)
I get the error 我收到了错误
Uncaught SyntaxError: Unexpected token N
I can't post the json since it is proprietary and gigantic. 我不能发布json,因为它是专有的和巨大的。 Why would I be getting this error if the JSON is generated by a well tested method?
如果JSON是由经过充分测试的方法生成的,为什么会出现此错误?
Use this tool to discover the problem: https://github.com/zaach/jsonlint 使用此工具发现问题: https : //github.com/zaach/jsonlint
The problem was due to Flask's jsonify allowing the serialization of NaN, but Google Chrome's implementation following the JSON spec and not allowing NaN. 问题是由于Flask的jsonify允许NaN的序列化,但谷歌Chrome的实现遵循JSON规范并且不允许NaN。
Some workarounds are listed here: How to parse JSON string containing "NaN" in Node.js 这里列出了一些解决方法: 如何解析Node.js中包含“NaN”的JSON字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.