$json="[{  
 'i':100000,  'u':-1,n: '中国'},{i:100001,u:-1,n:'阿尔巴尼亚'},{i:100002,u:-1,n:'阿尔及利亚',}]";
$json = preg_replace('/([{,:])(\s*)\'(.*?)\'/','$1"$3"',$json);//key、value的单引号变双引号 
$json = preg_replace('/([{,]+)(\s*)([^"\']+?)\s*:/','$1"$3":',$json);//没有单引号、双引号的key 两边加双引号
$json = preg_replace('/(,)\s*}/','}',$json);//去除尾部多于逗号
echo $json;
var_dump(json_decode($json));

 

function jsonstr_init($josn){
        $json = preg_replace('/([{,:])(\s*)\'(.*?)\'/','$1"$3"',$json);//key、value的单引号变双引号 
        $json = preg_replace('/([{,]+)(\s*)([^"\']+?)\s*:/','$1"$3":',$json);//没有单引号、双引号的key 两边加双引号
        $json = preg_replace('/(,)\s*}/','}',$json);//去除尾部多于逗号
        return $json;
}

 

相关文章:

  • 2022-12-23
  • 2021-11-28
  • 2021-08-11
  • 2021-12-27
  • 2021-10-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-11-27
  • 2021-12-02
  • 2021-12-06
相关资源
相似解决方案