在做辞职报告这个网站的时候,修改DEDE中因为有些内容用到了json发送内容到客户端,不知道大家是怎么做的.我写了以下函数实现function arr2json($arr,$charquote='"'){
$jsonstr='{';
foreach($arr as $key=>$msg){
if(is_array($msg)||is_object($msg)){
$jsonstr.=arr2json($msg,$charquote).',';
}else{
if(!is_numeric($msg)){$msg=$charquote.str_replace($charquote,"\\".$charquote,$msg).$charquote;}
if(is_numeric($key)){ $jsonstr.='n_'.$key.":".$msg.',';}else{$jsonstr.=$key.":".$msg.',';}
}
}

if(substr($jsonstr,-1,1)==','){
$jsonstr=substr($jsonstr,0,-1);
}
$jsonstr.='}';
return $jsonstr;
}我这种方法不知是否正确,请教大家有没有好的方法.