到网上找的资料基本都是这个函数
function ext_json_decode($str, $mode=false){
if(preg_match('/\w:/', $str)){
$str = preg_replace('/(\w+):/is', '"$1":', $str);
}
return json_decode($str, $mode);
}
这代码从逻辑上本身就是错误的,比如value里面有个:,解析自然出错,下面是修正过后的
function ext_json_decode($str, $mode=false){
$str = trim( $str );
$str = ltrim( $str, '(' );
$str = rtrim( $str, ')' );
$a = preg_split('#(?<!\\\\)\"#', $str );
for( $i=0; $i < count( $a ); $i+=2 ){
$s = $a[$i];
$s = preg_replace('#([^\s\[\]\{\}\:\,]+):#', '"\1":', $s );
$a[$i] = $s;
}
//var_dump($a);
$str = implode( '"', $a );
return json_decode($str, $mode);
}