<!DOCTYPE html> <html> <head> <title>test1.html</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="jquery/jquery-1.8.3.js"></script> <!--<link rel="stylesheet" type="text/css" href="./styles.css">--> <script type="text/javascript"> $(document).ready(function(){ //正则,匹配{}及里面的内容 var reg = /\{(.*?)\}/gi; //要操作的字符串 var str = 'http://localhost:8088/smartbi/vision/openresource.jsp?resid=I04e0bfda4a278aed014a812a40b94c48&user=agent_gd&password=Ab123456¶msInfo=[{"name":"user_head","value":"tpss_gz","displayValue":"tpss_gz"},{"name":"city_id","value":"200","displayValue":"200"},{"name":"cycle_id","value":"20150301","displayValue":"20150301"},{"name":"pro_ag_id","value":"","displayValue":""},{"name":"agent_id","value":"","displayValue":""},{"name":"chan_id","value":"60109235","displayValue":"60109235"},{"name":"gz_channel_type","value":"","displayValue":""},{"name":"agent_confirm_state","value":"2","displayValue":"2"}]&refresh=true'; var tmp = str.match(reg); if (tmp) { for (var i = 0; i < tmp.length; i++){ //匹配是否是需要的字符串 if(tmp[i].indexOf("agent_confirm_state")>0){ alert(tmp[i]); // 保留中括号 var obj = eval("("+tmp[i]+")");//转化为json对象 alert(obj.value);//获取json对象中value的值 } //alert(tmp[i].replace(reg, "$1")); // 不保留中括号 } } else { alert("no match."); } }); </script> </head> <body> </body> </html>