I have json data represented like this
{key:\"value\"}
(no quotes arround key...)
I want to translate it to an associative array.>
REGEX is totally not recommended for such cases, don't use that for parsing such data. If you have a simple goals and want to avoid the stable PEAR package
, then you might try JSON-php
library (but no-longer maintained).
1) Get JSON.phps
file from here and rename to .php
and replace constructor function names to __construct
.
2) usage:
$content = '{myKey:"valueeeee"}';
include(__DIR__.'/JSON.php');
$this->json = new Services_JSON( SERVICES_JSON_LOOSE_TYPE ); // to return objects instead of Associative array, remove the argument
var_dump( $this->json->decode($content) );