I am building a request in Flash that contains a JSON encoded Array of Objects. This is encoded using as3corelib. The request is then passed to JavaScript via ExternalInterface and a jquery ajax call sends the request off to the server.
In PHP, the incoming data is parsed, but the json_decode returns null, giving a Malformed JSON error. var_dump results in comments:
<?php
(isset($_POST['gdata']) && !empty($_POST['gdata'])) ? $gamedata = $_POST['gdata'] : returnError("game data not specified");
var_dump($gamedata); // (String) = string(37) "[{\"duration\":1,\"id\":\"game2\"}]"
$gamedata = json_decode(utf8_encode(trim($gamedata)),true);
var_dump($gamedata); // null
$gamedata = json_decode("[{\"duration\":1,\"id\":\"game2\"}]",true);
var_dump($gamedata);
/*
array(1) {
[0]=>
object(stdClass)#1 (2) {
["duration"]=>
int(1)
["id"]=>
string(7) "game2"
}
}
*/
?>
What I don't understand is that attempting to decode the variable returns null, but the same text decoded from a literal string works fine. What can I do to clean up the incoming data and make it readable for json_decode?
Edit: php_info()
says that magic_quotes_gpc is enabled. Could that be the issue?