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