[英]How to remove brackets from JSON
I have this JSON data:我有这个 JSON 数据:
var tmpStr = '[
{
"Name": "TEST",
"deviceId": "",
"CartId": "",
"timestamp": 1383197265540,
"FOOD": [],
"City": "LONDON CA"
}
]';
How can I delete the brackets?如何删除括号?
Here is more of my JSON file:这是我的 JSON 文件的更多内容:
[{"arrivee":false,"des":"Ceintures De Sécurité Conducteur","code":"nn","depart":true},
{"arrivee":true,"des":"Lecteur Tachygraphe","code":"nn","depart":false}
{"arrivee":false,"des":"Ceintures De Sécurités Passagères","code":"nn","depart":true},
{"arrivee":true,"des":"Climatisation","code":"nn","depart":false}]
你不必删除括号,只需这样做,
var result = tmpStr[0];
Parse the JSON string and use the first element of the array. 解析JSON字符串并使用数组的第一个元素。
var tmpStr = '[{"Name": "TEST","deviceId": "", "CartId": "", "timestamp": 383197265540, "FOOD": [], "City": "LONDON CA" }]', object = JSON.parse(tmpStr)[0]; console.log(object);
.as-console-wrapper { max-height: 100% !important; top: 0; }
Description:描述:
You wouldn't want to, this is a JSON array of Objects你不会想要的,这是一个 JSON 对象数组
[ // this starts an array
{ // this starts an object
"Name": "TEST", // this is a property named 'Name'
"deviceId": "", // this is a property named 'deviceId'
"CartId": "", // this is a property named 'CartId'
"timestamp": 1383197265540, // this is a property named 'timestamp'
"FOOD": [], // this is a property named 'FOOD'
"City": "LONDON CA" // this is a property named 'City'
} // this ends an object
] // this ends an array
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.