我有一个JSON,如下所示:
[{"type":"Point","coordinates":"[-77.03,38.90]"},"properties":{"city":3,"url":"xyz.com"}]
我想将
"[
替换为[
,将]"
替换为]
最佳答案
试试这个
$yourJson = [{"type":"Point","coordinates":"[-77.03,38.90]"},"properties":{"city":3,"url":"xyz.com"}];
$jsonString=preg_replace('/"([^"]+)"\s*:\s*/', '$1:', $yourJson);
$stringReplace=str_replace('"[', '[', $jsonString);
$stringReplace=str_replace(']"', ']', $stringReplace);
echo $stringReplace;