php json_decode fails without quotes on key

后端 未结 8 1933
故里飘歌
故里飘歌 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:17

    Please do not use regexps to do this! JSON grammar cannot be correctly parsed this way by definition. You will open yourself to a ton of future bugs.

    I recommend using a YAML parser, because YAML is a superset of JSON and allows unquoted literals at the same time.

    Symfony YAML component works great.

    There will be a performance penalty in comparison to json_decode which is implemented natively.

提交回复
热议问题