php json_decode fails without quotes on key

后端 未结 8 1912
故里飘歌
故里飘歌 2020-12-06 06:26

I have json data represented like this

{key:\"value\"}

(no quotes arround key...)

I want to translate it to an associative array.

8条回答
  •  北海茫月
    2020-12-06 07:09

    This worked for me, using regex replace '/\s(\w+)\s/i'

    $json =  file_get_contents("php://input"); // or whatever json data
    $json = preg_replace('/\s(\w+)\s/i', '"$1"', $json);
    $json = json_decode($json, true);
    

提交回复
热议问题