Stu*_*076 2 javascript arrays json object
这个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
}]
Run Code Online (Sandbox Code Playgroud)
它最有可能是逃脱字符的人,您是否尝试过转义\,所以无论您做什么都不会将其检测为换行符?
编辑:
我的意思是我刚刚做到了,它奏效了,试试这个:
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}]');
Run Code Online (Sandbox Code Playgroud)