简体   繁体   English

Javascript JSON.parse:Uncaught SyntaxError:意外的令牌N.

[英]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.

相关问题 未捕获到的SyntaxError:意外令牌[与JSON.parse - Uncaught SyntaxError: Unexpected token [ with JSON.parse "未捕获的 SyntaxError:带有 JSON.parse 的意外标记" - Uncaught SyntaxError: Unexpected token with JSON.parse 未捕获到的SyntaxError:JSON中的意外令牌u在JSON.parse的位置0 - Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse 未捕获的SyntaxError:JSON.parse中位置0的JSON中的意外标记a( <anonymous> ) - Uncaught SyntaxError: Unexpected token a in JSON at position 0 at JSON.parse (<anonymous>) 未捕获到的SyntaxError:JSON中的意外令牌&lt;在JSON.parse位置0处( <anonymous> ) - Uncaught SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) Uncaught SyntaxError: Unexpected token & in JSON at position 1 at JSON.parse (<anonymous> )</anonymous> - Uncaught SyntaxError: Unexpected token & in JSON at position 1 at JSON.parse (<anonymous>) 未捕获的语法错误:意外的令牌 c JSON.parse - Uncaught SyntaxError: Unexpected token c JSON.parse Uncaught SyntaxError:意外的令牌o- JSON.Parse - Uncaught SyntaxError: Unexpected token o- JSON.Parse JSON.parse()和$ .parseJSON()中的“未捕获的SyntaxError:意外的令牌?” - “Uncaught SyntaxError: Unexpected token ?” in both JSON.parse() and $.parseJSON() JSON.parse得到“Uncaught SyntaxError:Unexpected token h” - JSON.parse get “Uncaught SyntaxError: Unexpected token h”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM