{
"data": {
"app_id": "0000000",
"scopes": [
"public_profile"
],
"user_id": "00000000"
}
}
I want to get the USER ID with json_decode.
How do I get it?
{
"data": {
"app_id": "0000000",
"scopes": [
"public_profile"
],
"user_id": "00000000"
}
}
I want to get the USER ID with json_decode.
How do I get it?
$json = '{
"data": {
"app_id": "0000000",
"scopes": [
"public_profile"
],
"user_id": "00000000"
}
}';
//json_decode retornando um objeto
$object = json_decode($json);
$user_id = $object->{data}->{user_id};
//json_decode retornando um array associativo
$array_associativo = json_decode($json,true);
$user_id = $array_associativo['data']['user_id'];
Reference: php.net
Just use the variable that contains the JSON and use the index:
$json = json_decode(file_get_contents('php://input',true)); // <---- Usei esse exemplo, mas você pode usar qualquer "raw JSON"
// $json no momento contém o objeto total
$data = $json->{'data'};
$user_id = $data->{'user_id'};