php使用json代替serialize
需要注意的是 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);
}
}
您可能感兴趣的文章:
php使用json代替serialize
PHP中SERIALIZE和JSON序列化与反序列化的区别
json为什么像花儿一样红
PHP中json_encode、json_decode与serialize、unserialize
PHP中__sleep()方法详解
php JSON 数据格式化函数
用PHP将一个数组存到数据库的一个字段的方法
php序列化函数应用实例
PHP格式化输出json数据例子整理
PHP JSON转数组