简体   繁体   中英

Javascript JSON.parse: Uncaught SyntaxError: Unexpected token N

I have JSON data generated in Python using Flask's jsonify method.

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. Why would I be getting this error if the JSON is generated by a well tested method?

Use this tool to discover the problem: 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.

Some workarounds are listed here: How to parse JSON string containing "NaN" in Node.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM