我有一个JSON如下:
[{"type":"Point","coordinates":"[-77.03,38.90]"},"properties":{"city":3,"url":"xyz.com"}]
我想将"[
替换为[
,将]"
替换为]
答案 0 :(得分:3)
试试这个
$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;
答案 1 :(得分:0)
来自评论,您似乎将更多引用 “替换为试用此
json = json.replace("\"[","[");
答案 2 :(得分:0)
您可以使用following regex:
str.replace(/"(\[[^"\]]*\])"/, "$1");
其中str
是输入字符串。这将匹配"[
后跟一串不是"
和]
的字符串,后跟]"
,并将两个"
放在极端。在您的情况下,它会将"[-77.03,38.90]"
变为[-77.03,38.90]
。
除此之外,任何编码在问题中返回字符串的人都应该立即解雇 。