<?php<br />function json_to_array($web) {<br /> $arr=array();<br /> foreach($web as $k=>$v) {<br /> if(is_object($v)) $arr[$k]=json_to_array($v); //判斷類型是不是object<br /> else $arr[$k]=$v;<br /> }<br /> return $arr;<br />}<br />$s='{"webname":"homehf","url":"www.homehf.com","qq":"744348666"}';<br />//將字元轉成JSON<br />$web=json_decode($s);<br />$arr=array();<br />foreach($web as $k=>$v)<br /> $arr[$k]=$v;<br />echo "<pre>";<br />print_r($arr);<br />echo "</pre>";</p><p>$s='{"webname":"homehf","url":"www.homehf.com","contact":{"qq":"744348666","mail":"nieweihf@163.com","xx":"xxxxxxx"}}';<br />$web=json_decode($s);<br />$arr=json_to_array($web);<br />echo "<pre>";<br />print_r($arr);<br />echo "</pre>";</p><p>/************************************************************************<br />************************************************************************/<br />$s='{"webname":"homehf","url":"www.homehf.com","contact":{"qq":"744348666","mail":"nieweihf@163.com","xx":"xxxxxxx"}}';<br />$web=json_decode($s);<br />echo '網站名稱:'.$web->webname.'<br />網址:'.$web->url.'<br />連絡方式:QQ-'.$web->contact->qq.' MAIL:'.$web->contact->mail;<br />echo '<br /><br />';<br />/************************************************************************<br />************************************************************************/<br />$s='{"webname":"homehf","url":"www.homehf.com","contact":{"qq":"744348666","mail":"nieweihf@163.com","xx":"xxxxxxx"}}';<br />$web=json_decode($s);<br />echo json_encode($web);<br />