PHP与js使用json交互

$m_register_array = array();
$m_register_json =  urlencode(iconv("GB2312","UTF-8",json_encode($m_register_array)));
PHP代码
function URLdecode(str) {
   var ret = "";
   for(var i=0;i<str.length;i++) {
      var chr = str.charAt(i);
      if(chr == "+") {
         ret += " ";
      }else if(chr=="%") {
         var asc = str.substring(i+1,i+3);
         if(parseInt("0x"+asc)>0x7f) {
            ret += decodeURI("%"+ str.substring(i+1,i+9));
            i += 8;
         }else {
            ret += String.fromCharCode(parseInt("0x"+asc));
            i += 2;
         }
      }else {
         ret += chr;
      }
   }
   return ret;
}
var styleJson = eval(URLdecode("<?php echo $m_register_json ?>"));  //比赛类型json数据
js代码

相关推荐