0

I've managed to send some parameters via POST to a .php file. When I invoke var_dump($_POST);, I get the following output:

["{"abc":"1","def":"2"}"]=>
string(0) ""

I've tried to process this many, many times but I can't seem to access the variables inside the String. json_decode doesn't even work on it. What's going on here?

Wakka02
  • 1,491
  • 4
  • 28
  • 44

1 Answers1

1

Somehow you have managed to transmit your data with its value as the key and no attached value, so you need to address that in whatever code is accessing the server (Perhaps you used JSON.Stringify on the object instead of just passing the object?). Until you have fixed that, you can access your data like this:

$json = json_decode(array_keys($_POST)[0]);
print_r($json);

Output:

stdClass Object (
    [abc] => 1
    [def] => 2 
)
Nick
  • 138,499
  • 22
  • 57
  • 95