0

Below is the example json code i am trying to parse using php.

{
    "educations": {
        "_total": 7
    }
}

I tried it parsing using the following php code. But i am making some silly mistake which i am unable to find. Below is the PHP code

<?php

$decoded = json_decode($json_string)
echo "$decoded->educations->_total";

?>

but I am not getting some object error which i am unable to figure out.

The error is: Catchable fatal error: Object of class stdClass could not be converted to string

PLease help thanks.

Susheel Singh
  • 3,824
  • 5
  • 31
  • 66

2 Answers2

0

Try accessing your returned json object as an array

$total = $decoded['educations']['_total'];
Gigline
  • 297
  • 1
  • 4
0

Sorry My silly mistake:

$total= "$decoded->educations->_total";

I added a double quote which created this problem. The below code is the correct one.

<?php

$decoded = json_decode($json_string)
echo $decoded->educations->_total;

?>
Susheel Singh
  • 3,824
  • 5
  • 31
  • 66