Is there a way to retreive a key from JSON string with out going in to foreach loop?
$json ="{\"error\":{\"code\":301}}";
if (empty($json)) {
die('empty string');
} else {
$obj = json_decode($json);
foreach ($obj as $key => $object) {
echo $key;
}
}
What I need is to detect where the string contains error or not, so I can create error handling.
Thanks in advance