javascript - 这个 JSON 字符串有什么问题?它也适用于 JSONLint
问题描述
这个 JSON 字符串似乎是无效的,但是当我用 JSONLint 检查它时它说它是有效的,所以问题出在哪里。错误在位置 252 处弹出。
let test = JSON.parse('[{"id":6,"item_type":"cybro_unit","unitId":6,"pos_id":9,"name":"CyBro-2","image":"images/cybro/defaultBro.png","layer":"10","positionX":111.0,"positionY":249.0,"layerName":"10","sizeX":201.0,"sizeY":168.0,"z_index":9999,"showLabel":true,"hint":"CyBro-2\nPovezan: true\nVelikost X: 201.523163\nVelikost Y: 168.675491","enabled":true,"connected":false}]');
[{
"id": 6,
"item_type": "cybro_unit",
"unitId": 6,
"pos_id": 9,
"name": "CyBro-2",
"image": "images/cybro/defaultBro.png",
"layer": "10",
"positionX": 111.0,
"positionY": 249.0,
"layerName": "10",
"sizeX": 201.0,
"sizeY": 168.0,
"z_index": 9999,
"showLabel": true,
"hint": "CyBro-2\nPovezan: true\nVelikost X: 201.523163\nVelikost Y: 168.675491", // here at CyBro-2
"enabled": true,
"connected": false
}]
解决方案
最有可能是转义字符的人,您是否尝试过转义 \ 所以无论您在做什么都不会将其检测为换行符?
编辑:
我的意思是我刚刚做到了,它奏效了,试试这个:
JSON.parse('[{"id":6,"item_type":"cybro_unit","unitId":6,"pos_id":9,"name":"CyBro-2","image":"images/cybro/defaultBro.png","layer":"10","positionX":111.0,"positionY":249.0,"layerName":"10","sizeX":201.0,"sizeY":168.0,"z_index":9999,"showLabel":true,"hint":"CyBro-2\\nPovezan: true\\nVelikost X: 201.523163\\nVelikost Y: 168.675491","enabled":true,"connected":false}]');
推荐阅读
- linux - 使用 Linux CLI 音频处理工具构建软件鹦鹉中继器?
- terraform-provider-aws - 属性 cidr_block 字符串的值不正确是必需的
- python - 如何安全地销毁列表中加入的多处理对象?
- java - 将 SpringData 与 Spring MVC 一起使用
- sql - SQL (BigQuery) 每天分组运行时
- java - 使用 Spring Boot 机制将 JSON 文件读取为地图
- javascript - 服务器端渲染(Express/React),提供未定义路由的文件
- discord.py - 结合命令和事件
- unity3d - Unity,如何正确设置Pixels32?
- python - 如何将计数器元素添加到元组中的 *each* 重复值?