类与json
<?php class userinfo { var $user_name; var $user_ip; var $user_logintime; } $u = new userinfo(); $u->user_name = "贝尔塔猫"; $u->user_logintime = time(); $u->user_ip = "127.0.0.1"; $strjson = serialize($u); //序列化为字符串json $a = new userinfo(); //必须“重新加载”并且“重新实例化”一个类,否则会报错 $a = unserialize($strjson); //反序列化为类 print_r($a ); ?>
数组与json
<php $arr = array("Msg" => $Msg,"Result" => $Result,"Status" => $Status); $strjson = json_encode($arr); //将数组序列化为字符串json $arrjson = json_decode($strjson); //将字符串反序列化为数组 ?>