I have this JSON data:
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:
[{"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}]
I have this JSON data:
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:
[{"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}]
Share
Improve this question
edited Oct 16, 2016 at 22:16
Heretic Monkey
12.1k7 gold badges61 silver badges131 bronze badges
asked Oct 16, 2016 at 17:14
user6893264user6893264
3 Answers
Reset to default 3Parse the JSON string and use the first element of the array.
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; }
You dont have to delete brackes, just do this,
var result = tmpStr[0];
Description:
You wouldn't want to, this is a JSON array of Objects
[ // 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