没有双引号的JSON格式,有什么办法用PHP解开吗。
格式如:{name: "brandId1", type: "String1"}
json的标准格式应该是key有双引号,目前第三方数据无引号,请问有什么办法可以解开为数组吗

解决方案 »

  1.   

    $s = <<< JSON
    {name: "brandId1", type: "String1"}
    JSON;print_r(ex_json_decode($s));function ex_json_decode($s, $mode=false) {
      if(preg_match('/\w:/', $s))
        $s = preg_replace('/(\w+):/is', '"$1":', $s);
      return json_decode($s, $mode);
    }stdClass Object
    (
        [name] => brandId1
        [type] => String1
    )判别算法不够完备,请自行完善