2016-10-16 34 views
-3

からブラケットを削除する方法:私は、この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}] 

答えて

2

あなたはちょうどこの、

var result = tmpStr[0]; 
+0

のJSON配列はウル答えをuと感謝が、それは私にエラーを与えています:JSONの1位の予期しないトークンo –

+0

@estemestem JSONが投稿したものと異なります。投稿したJSONが適切に構成されているためです。 – abc123

+0

は実際には私の本当のjsonファイルです:[{"arrivee":false、 "des": "Ceontures DeSécuritéConducteur"、 "code": "nn"、 "depart":true}、{"arrivee" "des": "Lecteur Tachygraphe"、 "code": "nn"、 "depart":false}、{"arrivee":false、 "d es": "Ceintures DeSécuritésPassagères"、 "code" "nn"、 "depart":true}、{"arrivee":true、 "des": "Climatisation"、 "co de": "nn"、 "depart":fa lse}] –

1

ParseJSON文字列操作を行うと、配列の最初の要素を使用し、brackesを削除するには持っていけません。

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

+0

URのお返事ありがとうございますが、私にエラーが表示されます:1のJSONで予期しないトークンo –

+1

質問にどんなフォーマットも付いていない文字列を追加してください。どこから文字列を取得しますか? –

+0

実際には私は多くのオブジェクトを持っているだけでなく、エラーを見つけるために –

2

説明:あなたがしたいとは思わないでしょう
、これはオブジェクト

[ // 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 
+0

は実際には私の本当のjsonファイルです:[{"arrivee":false、 "des": "Ceontures DeSécuritéConducteur"、 "code": "nn"、 "depart":true}、{"arrivee" "des": "Lecteur Tachygraphe"、 "code": "nn"、 "depart":false}、{"arrivee":false、 "d es": "Ceintures DeSécuritésPassagères"、 "code" "到着":true、 "des": "Climatisation"、 "co de": "nn"、 "depart":fa lse}] –

+0

@estemestem "nn"、 "depart"あなたは無効なJSONを取得しています。これはシンボル文字を含む文字列のためです(IEはフランス語) – abc123

+1

フランス語であるという事実は問題ではありません(文字列値はエスケープ文字を除く有効なUnicode文字です)。問題は、無効な(非表示の)文字が多数含まれているため、JSON(投稿済み)が無効であることです。 [JSONLint](http://jsonlint.com/)のようなリンターを介してJSONを実行すると、それらが表示されます。 –

関連する問題