2016-10-05 28 views
0

下面是一個完整的字符串,如何將字符串從「{」拆分爲「}」意味着需要完整的對象。從給定的最後一個特定關鍵字字符串拆分

% Total % Received % Xferd Average Speed Time Time  Time Current 
           Dload Upload Total Spent Left Speed 
100 234 0 159 100 75 584 275 --:--:-- --:--:-- --:--:-- 584 
{"scope":"Production","token_type":"bearer","expires_in":78,"refresh_token":"eregfgfg","access_token":"swewe23231c323"} 

需要結果:

{"scope":"Production","token_type":"bearer","expires_in":78,"refresh_token":"eregfgfg","access_token":"swewe23231c323"} 
+0

請詳細說明您需要從您那裏得到的問題真的很難理解您的要求 – Tanmay

+1

嘗試'json.parse()' –

+0

_how將字符串從「 {「到」}「_ - > Fi x服務器的響應 – Andreas

回答

0

這是很簡單的......

var yourObj = yourStr.substring(yourStr.indexof('{'), yourstring.length-1); 

OR

var yourObj = yourStr.substring(yourStr.indexof('{'), yourStr.indexof('}')); 

朋友,這隻會如果你的字符串將工作就像你上面寫的一樣。

+0

不行不行... –

1

嘗試此

JSON.parse(yourobject) 
0

使用正則表達式

var a = ' % Total % Received % Xferd Average Speed Time Time  Time Curren Dload Upload Total Spent Left Speed 100 234 0 159 100 75 584 275 --:--:-- --:--:-- --:--:-- 584 {"scope":"Production","token_type":"bearer","expires_in":78,"refresh_token":"eregfgfg","access_token":"swewe23231c323"}'; 

console.log((/(\{.*\})/gmi).exec(a)[0]); 

顯示: 「{」 範圍 「:」 生產 「 」token_type「: 」承載「, 」expires_in「:78,」 refresh_token 「:」eregfgfg「,」access_token「:」swewe23231c323「}」

相關問題