<?php function json_to_array($web) { $arr=array(); foreach($web as $k=>$v) { if(is_object($v)) $arr[$k]=json_to_array($v); //判断类型是不是object else $arr[$k]=$v; } return $arr; } $s='{"webname":"homehf","url":"www.homehf.com","qq":"744348666"}'; //将字符转成JSON $web=json_decode($s); $arr=array(); foreach($web as $k=>$v) $arr[$k]=$v; echo "<pre>"; print_r($arr); echo "</pre>"; $s='{"webname":"homehf","url":"www.homehf.com","contact":{"qq":"744348666","mail":"nieweihf@163.com","xx":"xxxxxxx"}}'; $web=json_decode($s); $arr=json_to_array($web); echo "<pre>"; print_r($arr); echo "</pre>"; /************************************************************************ ************************************************************************/ $s='{"webname":"homehf","url":"www.homehf.com","contact":{"qq":"744348666","mail":"nieweihf@163.com","xx":"xxxxxxx"}}'; $web=json_decode($s); echo '网站名称:'.$web->webname.'<br />网址:'.$web->url.'<br />联系方式:QQ-'.$web->contact->qq.' MAIL:'.$web->contact->mail; echo '<br /><br />'; /************************************************************************ ************************************************************************/ $s='{"webname":"homehf","url":"www.homehf.com","contact":{"qq":"744348666","mail":"nieweihf@163.com","xx":"xxxxxxx"}}'; $web=json_decode($s); echo json_encode($web);