Get JSON post parameter in PHP

I am sending a JSON parameter to my PHP script, which looks like this:

[{"Username":"john"}]

I would like to get the john value in PHP, and this is what I use to get JSON:

$json = file_get_contents('php://input');

After that, how can I access the value and store it in a variable?

EDIT:

I tried the following, but this does not work.

$data = json_decode($json);

$username=$data->{"Username"};
+1
source share

Source: https://habr.com/ru/post/1649480/


All Articles