$json="[{' I ': 100000, ' U ': -1,n: ' China '},{i:100001,u:-1,n: ' Albania '},{i:100002,u:-1,n: ' Algeria ',}]";$json=Preg_replace('/([{,:]) (\s*) \ ' (. *?) \ '/', ' $ $ ',$json);//single quotation marks for key and value$json=Preg_replace('/([{,]+) (\s*) ([^ "\ ']+?) \s*:/', ' $ "$": ',$json);//double quotation marks on both sides of a key without single or double quotation marks$json=Preg_replace('/(,) \s*}/', '} ',$json);//remove tail more than commaEcho $json;Var_dump(Json_decode ($json));
functionJsonstr_init ($josn){ $json=Preg_replace('/([{,:]) (\s*) \ ' (. *?) \ '/', ' $ $ ',$json);//single quotation marks for key and value $json=Preg_replace('/([{,]+) (\s*) ([^ "\ ']+?) \s*:/', ' $ "$": ',$json);//double quotation marks on both sides of a key without single or double quotation marks $json=Preg_replace('/(,) \s*}/', '} ',$json);//remove tail more than comma return $json;}
PHP JSON initialization function (format JSON string as PHP Json_decode standard string)