教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 php使用json代替serialize

php使用json代替serialize

发布时间:2016-10-26   编辑:jiaochengji.com
教程集为您提供php使用json代替serialize等资源,欢迎您收藏本站,我们将为您提供最新的php使用json代替serialize资源
php使用json代替serialize,有需要的朋友可参考一下。

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

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

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1743')">复制代码</td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1743>

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=&gt;$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转数组

[关闭]
~ ~