Home >Backend Development >PHP Problem >What to do if php json has no quotation marks

What to do if php json has no quotation marks

藏色散人
藏色散人Original
2021-05-10 11:02:572834browse

php json没有引号的解决办法:首先创建一个PHP示例文件;然后通过“function ex_json_decode($s, $mode=false) {...}”方法解决json没有引号的问题即可。

What to do if php json has no quotation marks

本文操作环境:Windows7系统、PHP7.1版,DELL G3电脑

具体问题:

没有双引号的JSON格式,有什么办法用PHP解开吗。

格式如:{name: "brandId1", type: "String1"}

json的标准格式应该是key有双引号,目前第三方数据无引号,请问有什么办法可以解开为数组吗

解决方案:

PHP代码如:

$s = <<< JSON
{name: "brandId1", type: "String1"}
JSON;
print_r(ex_json_decode($s));
function ex_json_decode($s, $mode=false) {
  if(preg_match(&#39;/\w:/&#39;, $s))
    $s = preg_replace(&#39;/(\w+):/is&#39;, &#39;"$1":&#39;, $s);
  return json_decode($s, $mode);
}

推荐学习:《PHP视频教程

The above is the detailed content of What to do if php json has no quotation marks. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn