简体   繁体   中英

How to remove brackets from JSON

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,"d‌​‌​es":"Ceintures De Sécurités Passagères","code":"nn","depart":true},
 {"arrivee":true,"des"‌​‌​:"Climatisation","‌​co‌​de":"nn","depart‌​":fa‌​lse}]

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

var result = tmpStr[0];

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM