意外的令牌与有效的JSON?
为什么我不能打印这个简单的JSON? jsonlint.com说这是有效的
JSON:
[ { "token_start_offset": "0.00", "token_duration": "4.00", "token_base_start_offset": "0.00", "token_base_duration": "4.00", "token_type": "background_noise", "token_background_noise_type": "other", "session_id": "1459194633575", "token_base_form": "…", "token_print_form": "…", "session_boundary": "begin", "nonspeech_boundary": "begin", "token_id": "0" } ]
app.js:
var testJson = require('./json'); console.log(testJson);
但是当我运行这个,我得到了下面的错误:
错误:
module.js:428 throw err; ^ SyntaxError: C:\Users\Owner\Desktop\format test\json.json: Unexpected token at Object.parse (native) at Object.Module._extensions..json (module.js:425:27) at Module.load (module.js:344:32) at Function.Module._load (module.js:301:12) at Module.require (module.js:354:17) at require (internal/module.js:12:17) at Object.<anonymous> (C:\Users\Owner\Desktop\format test\app.js:1:78) at Module._compile (module.js:410:26) at Object.Module._extensions..js (module.js:417:10) at Module.load (module.js:344:32)
Windows 10节点-v 4.2.6
因为Node的require()
的JSONparsing器采用ASCII字符,而您的示例包含Unicode字符: …
如果你用\u2026
replace…的所有实例,你的JSON应该被parsing。
我发现了一些工作
我在这里input我的json http://codebeautify.org/jsonvalidate
它能够find隐藏的空白字符,我可以删除并重新validation,直到没有更多的错误被发现。