2016-02-09 132 views
1

JSON字符串我的Ajax請求的響應文本是這樣的:得到Ajax響應文本

"<json> 
<![CDATA[ 
{"status":true,"filterMap":{ "summary":"Summary","total":"Total","myProfileMsg":"Opening my profile, please wait","cgBase":"CG Base","export1":"Export"}} 
]]> 
<offsetinTime>19800000</offsetinTime></json>" 

我想從這個只提取JSON字符串..即。我想要的是:

{"status":true,"filterMap":{ "summary":"Summary","total":"Total","myProfileMsg":"Opening my profile, please wait","cgBase":"CG Base","export1":"Export"}} 

我該怎麼做?

回答

1

使用字符串的replace() & split()功能實現它:

var json ='<json><![CDATA[{"status":true,"filterMap":{"summary":"Summary","total":"Total","myProfileMsg":"Opening my profile, please wait","cgBase":"CG Base","export1":"Export"}}]]><offsetinTime>19800000</offsetinTime></json>'; 
 
var extractedJson=json.replace('<json><![CDATA[','').split(']')[0]; 
 
document.body.innerHTML=extractedJson;