如何从JSON

时间:2016-10-16 17:14:16

标签: javascript angularjs json

我有这个JSON数据:

var tmpStr = '[    
{
    "Name": "TEST",
    "deviceId": "",
    "CartId": "",
    "timestamp": 1383197265540,
    "FOOD": [],
    "City": "LONDON CA"
 }

]';

如何删除括号?

这是我的更多JSON文件:

[{"arrivee":false,"des":"Ceintures De Sécurité Conducteur","code":"nn","depart":true},
 {"arrivee":true,"des"‌​‌​:"Lecteur Tachygraphe","code":"nn","depart":false}
 {"arrivee":false,"d‌​‌​es":"Ceintures De Sécurités Passagères","code":"nn","depart":true},
 {"arrivee":true,"des"‌​‌​:"Climatisation","‌​co‌​de":"nn","depart‌​":fa‌​lse}]

3 个答案:

答案 0 :(得分:2)

你不必删除括号,只需这样做,

catch

答案 1 :(得分:2)

说明
你不会想要的,这是一个对象的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

答案 2 :(得分:1)

Parse 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; }