作者:xaony23625 | 来源:互联网 | 2018-04-22 21:46
public static function encode(&$var)
{
return '{'.implode(',',self::encodeExcute($var)).'}';
}
private static function encodeExcute(&$var)
{
$json = array();
switch (gettype($var))
{
case 'array':
foreach($var as $key=>$value)
{
if(is_array($value))
{
$json[] = '"'.$key.'":{'.implode(',',self::encodeExcute($value)).'}';
//$json[$key] = self::encode($value);
} elseif (is_object($value)) {
$json[] = "\"{$key}\":".json_encode($value->attributes);
} else {
echo 'ERROR 未知类型,还未解析';
Yii::app()->end();
}
}
break;
case 'object':
break;
}
return $json;
}