我有一个像下面这样的json字符串
[
{
"Name": "TEST",
"deviceId": "",
"CartId": "",
"timestamp": 1383197265540,
"FOOD": [],
"City": "LONDON CA"
}
]
我想从字符串中删除/删除第一个和最后一个方括号。那么如何使用javascript从上面的字符串中删除第一个和最后一个方括号。
请帮帮我
答案 0 :(得分:8)
返回时使用此项:
return properties[0];
或者
var data = [
{
"Name": "TEST",
"deviceId": "",
"CartId": "",
"timestamp": 1383197265540,
"FOOD": [],
"City": "LONDON CA"
}
]; // Or whatever the Json is
data = data[0];
或者,如果您通过其他对象访问json
var data = jsonObj[0];
答案 1 :(得分:6)
var tmpStr = '[
{
"Name": "TEST",
"deviceId": "",
"CartId": "",
"timestamp": 1383197265540,
"FOOD": [],
"City": "LONDON CA"
}
]';
var newStr = tmpStr.substring(1, tmpStr .length-1);
答案 2 :(得分:4)
试试这个:
var A = [{}]; var B = {}; A = [
{
"Name": "TEST",
"deviceId": "",
"CartId": "",
"timestamp": 1383197265540,
"FOOD": [],
"City": "LONDON CA"
}
]
B = A[0]; console.log(B); //required output