我的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"}}
我该怎么做?
答案 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;