json - JSON 解析 -SyntaxError: 位置 72 处 JSON 中的意外标记
问题描述
我已经生成了几个单行 JSON 文件(来自 excel)——我试图通过 cordova 移动应用程序读取这些文件。该文件正在被读取,但问题是解析它示例在线 Json 文件:注意文件正在被读取
在onloadend里面:
{"name":"Acrobat Ant","id":"500","category":"Ants","features":{"format": {"cn":"hd_lst" ,"fm":"inline","edit": 0},"npma":"1.Ants//13.Wood-infesting Insects","compare2":"","length":"Adults 2.5-4mm // Queen 10mm","color":"Brown to black // "... (this is only partial
Error in Success callbackId: File899903995 : SyntaxError: Unexpected token in JSON at position 72
cordova.js:310 SyntaxError: Unexpected token in JSON at position 72
at JSON.parse (<anonymous>)
at FileReader.reader.onloadend (plugins.js:188)
at FileReader.readSuccessCallback (plugins/cordova-plugin-file/www/FileReader.js:164)
at Object.callbackFromNative (cordova.js:291)
at <anonymous>:1:9
这发生在我尝试的单个文件中。该位置 72(对于此文件)位于
冒号之前的 {"format" 单词的末尾:正如我所说,除了位置更改之外的所有其他文件都会发生这种情况,但所有文件都在格式属性的末尾完全失败。
我使用https://jslint.com/检查单行 JSON 的语法,它说很好。奇怪的是,如果将一个衬里更改为分层格式(通过可视代码 Shift-ALt-F),因为下面显示的示例分解 JSON 可以毫无问题地解析。
{
"name": "Acrobat Ant",
"id": "500",
"category": "Ants",
"features": {
"format": {
"cn": "hd_lst",
"fm": "inline",
"edit": 0
},
....etc
顺便说一句,一行 JSON 文件是从 Excel 生成的,并保存为 UTF8 without BOM。(如果我尝试使用 BOM 解析它会失败。)所以我的困境是我有超过 200 个文件,我希望它们在创建后立即读取,而无需执行手动额外步骤将它们变成分层格式 JSON。
仅供参考,我完全使用了有关如何从 VBA 将 excel 数据保存到没有 BOM 的 UTF8 的建议:save a file with UTF-8 without BOM
请指教
解决方案
推荐阅读
- c++ - 由并发无序映射查找线程调用的函数是否安全?
- mysql - MYSQL:错误代码:1054。“where 子句”中的未知列
- c++11 - 初始化 GTest const 类成员
- eclipse - 无法将 Eclipse 项目共享到新的 GIT 存储库,因为资源已存在
- angular - RxJs 在第一次 Emit 时跳过示例,等待一个 Observable 完成
- c++ - 使用 Mutex 挂起程序
- asp.net-core - 使用 ASP.NET Core 2.1 的本地化页面名称
- php - Wordpress 查询自定义帖子类型新增功能
- c++ - 用 Eigen 3 计算数组的特征值/向量而不是矩阵
- xslt-2.0 - 在 xslt 中将两条记录连接成一条记录