SplitV that seemed logical. It even works if I pick JS out of the process…
This works (php):
$json = '{"json": {"color" : "red"}}'; $props = json_decode($json, true); $return['msg'] = $props["json"]["color"]; echo json_encode($return);
“red” is the value of “msg” this way.
But if I get the JSON serialized string from JS (which I assume is the same as I hardcoded in the previous example:
JS:
data : { "json" : $.toJSON(something)},
PHP:
$props = json_decode($_POST['json'], true); $return['msg'] = $props["json"]["color"]; echo json_encode($return);
The value of “msg” in the return is just “null” (invalid JSON, right?)
Isn’t this { “json” : $.toJSON(something)} producing {“json”: {“color” : “red”}}?