I want to parse following json for value of
JSON (saved in my.json):
{
"mackoniv":{"entry":"","lastExit":"","userId":"OPENGOVTJOBS","userNick":"mack"},
"johanna":{"entry":"","lastExit":"","userId":"FREEJOBALERT","userNick":"jone"}
}
Code used :
$json = file_get_contents('my.json');
$json_data = json_decode($json,true);
$userToCheck='johanna';
echo 'userId'.$json_data->$userToCheck->userId;
The above code gives error "Trying to get property of non-object", which i understand as $userToCheck isnt an object of $json_data but how do i access the data of "mackoniv" or even "johanna" when userToCheck part is not to be hardcoded.
If i try following way, it gives same error.
echo 'userId'.$json_data[$userToCheck]['userId'];