I am receiving a JSON string from an API, which I am then decoding into an array. The array is full of stdClass Objects and arrays, but I cannot seem to access the properties.
This is the array I have decoded from JSON and then called print_r on:
stdClass Object
(
[scannedDocument] => stdClass Object
(
[scanId] => 6188703b5450ed927159cbbbb223fc89
[totalWords] => 7
[totalExcluded] => 0
[credits] => 1
[creationTime] => 2019-10-21T10:33:18
)
[results] => stdClass Object
(
[internet] => Array
(
)
[database] => Array
(
)
[batch] => Array
(
)
[score] => stdClass Object
(
[identicalWords] => 0
[minorChangedWords] => 0
[relatedMeaningWords] => 0
[aggregatedScore] => 0
)
)
[status] => 0
)
I am assuming I should access the first value of the array and then using -> to get to the object values like this:
$wordcount = $jsonResponse[0]->scannedDocument->totalWords;
$totalExcluded = $jsonResponse[0]->scannedDocument->totalExcluded;
$percent = $jsonResponse[0]->results->score->aggregatedScore;
But these variables are blank. I am tearing my hair out!
Any ideas please?