2014-03-12 109 views
1

刪除字符串我收到這樣的迴應:如何從JSON響應

/*-secure-{"errors":["Runtime: Adapter 'DemoAdapter' does not exist"],"isSuccessful":false,"warnings":[],"info":[]}*/ 

但我只想從響應JSON數據。就像這樣:

{ 
"errors":  ["Runtime: Adapter 'DemoAdapter' does not exist"], 
"isSuccessful": false, 
"warnings":  [], 
"info":   [] 
} 

如何從響應的末尾移除從一開始就/*-secure-*/

+5

Json不能評論,你從哪裏得到這樣的回覆? – xdazz

+0

我得到了響應IBM Worklight服務器。 – manjakannar

+5

@xdazz:這可能是爲了防止人們竊取JSON; –

回答

1

我得到了答案:

var str = '/*-secure-{"errors":["Runtime: Adapter "DemoAdapte" does not exist"],"isSuccessful":false,"warnings":[],"info":[]}*/'; 
var res = str.substring(10,str .length-2); 

語法是這樣的。

var str = data; 
var res = str.substring(10,str .length-2); 

其中數據是任何字符串你得到的迴應。

1

應該是一個簡單的替換:

var resp = <string>; 
resp = resp.replace(/^\/\*\-secure\-\n/, '').replace(/\*\/$/, ''); 
+0

在字符串中我如何傳遞整個字符串。 「/ * - secure - {」errors「:[」Runtime:Adapter'DemoAdapter'does not exist「],」isSuccessful「:false,」warnings「:[],」info「:[]} * /」。每個json對象都有雙重代碼(「)。 – manjakannar

+0

嘗試轉義它:」這是一個\「quote \」。「 – beautifulcoder