Well I need to make a handling of an error while retrieving a field from a json.
I have the following Json:
{
"Autenticacao": {
"login": "123",
"senha": "123"
}
}
I'm recovering the data like this:
// Decodifica o Json
$obj = json_decode($json);
$obj->autenticacao->login;
So far so good, the problem is when the user informs a json that contains an array, like this:
{
"Autenticacao": [{
"login": "123",
"senha": "123"
}]
}
With this php gives the following error:
Notice: Trying to get property of non-object in
What happens on the line:
$obj->autenticacao->login;
How can I handle this error and tell the user that json is not correct.