Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
是否有任何在线工具可以将无效JSON中的单引号替换为双引号,或者有任何解决方案可以在PHP中使用无效JSON?_Php_Json_Single Quotes - Fatal编程技术网

是否有任何在线工具可以将无效JSON中的单引号替换为双引号,或者有任何解决方案可以在PHP中使用无效JSON?

是否有任何在线工具可以将无效JSON中的单引号替换为双引号,或者有任何解决方案可以在PHP中使用无效JSON?,php,json,single-quotes,Php,Json,Single Quotes,我有很多invliad JSON文件 这是无效JSON文件的片段 [ { 'name':'Arden', 'born':'1973-12-22', 'orientation':'Heterosexual', 'purpose':'Friendship', 'tags':'cooking,swimming,adventure,drawing', 'country':'United Kingdom::Edinburgh', 'about

我有很多invliad JSON文件

这是无效JSON文件的片段

[
    {
    'name':'Arden',
    'born':'1973-12-22',
    'orientation':'Heterosexual',
    'purpose':'Friendship',
    'tags':'cooking,swimming,adventure,drawing',
    'country':'United Kingdom::Edinburgh',
    'about':'I often read (and enjoy!) things that are completely opposed to everything I believe. I've enjoyed.'
    },

    {
    'name':'Sisera',
    'born':'1962-01-25',
    'orientation':'Homosexual',
    'purpose':'Flirt',
    'tags':'reading,fishing,tennis,theater',
    'country':'United States::Fairfield',
    'about':'I'm OCD about shoes being placed side-by-side. I don't like them together by the door.'
    }
]
如何将此单引号替换为双引号? PHP中是否有任何在线工具或解决方案

我想要的是:

[
    {
    "name":"Arden",
    "born":"1973-12-22",
    "orientation":"Heterosexual",
    "purpose":"Friendship",
    "tags":"cooking,swimming,adventure,drawing",
    "country":"United Kingdom::Edinburgh",
    "about":"I often read (and enjoy!) things that are completely opposed to everything I believe. I\'ve enjoyed."
    },

    {
    "name":"Sisera",
    "born":"1962-01-25",
    "orientation":"Homosexual",
    "purpose":"Flirt",
    "tags":"reading,fishing,tennis,theater",
    "country":"United States::Fairfield",
    "about":"I\'m OCD about shoes being placed side-by-side. I don\'t like them together by the door."
    }
]
提前谢谢。

你可以用这个

str_replace("'",'"',$jsonstring)
对于联机工具,可以使用此格式化程序

如super建议的preg_更换。代码应该是这样的

preg_replace("/',/", '",', preg_replace("/':'/", '":"', preg_replace('/[ \t]+/', ' ', preg_replace("/[\r\n]+\s*[']\s*/", "\n\"", $jsonstring))));
你可以用这个

str_replace("'",'"',$jsonstring)
对于联机工具,可以使用此格式化程序

如super建议的preg_更换。代码应该是这样的

preg_replace("/',/", '",', preg_replace("/':'/", '":"', preg_replace('/[ \t]+/', ' ', preg_replace("/[\r\n]+\s*[']\s*/", "\n\"", $jsonstring))));

非常感谢。在线工具很酷,正则表达式不起作用。另一个问题是,无效的json在there值中包含单引号,比如“can't,I'll,don't”,它无论如何都不起作用,我已经更新了无效和有效的json示例,你能检查一下吗?谢谢。在线工具很酷,正则表达式不起作用。另一个问题是,无效的json在there值中包含单引号,比如“can't,I'll,don't”,它无论如何都不起作用,我已经更新了无效和有效的json示例,你能检查一下吗?