php使用json代替serialize

作者:简简单单 2012-11-15

需要注意的是 json_decode时返回的是object,需要

json_decode("字符串",ture);后来发现也不是那么完美..
json_encode会对中文进行编码.如果含有大量的中文,那长度超过了serialize.
这让人很蛋疼,网上给出的办法是对内容进行urlencode,json_enocde后再urldecode

 代码如下 复制代码

function jsonencode($code){ //新json_encode
 $code = json_encode(urlencodearray($code));//对数组处理
 return urldecode($code);
}

function urlencodearray($data){//urlencode数组
 if(is_array($data)){
 foreach($data as $key=>$val){
 $data[$key] = urlencodearray($val);
 }
 return $data;
 }else{
 return urlencode($data);
 }
}

相关文章

精彩推荐