从ajax响应文本中获取json字符串

时间:2016-02-09 06:49:08

标签: ajax extjs

我的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字符串.. ie。我想要的是:

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

我该怎么做?

1 个答案:

答案 0 :(得分:1)

使用replace()&amp; 字符串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;