How to Json Decode in PHP using Services_JSON package of pear(PHP Catchable fatal error: Object of class stdClass could not be converted to string ) -
i want encode/decode array using json . have php 5.1.6 , using pear's (http://pear.php.net/pepr/pepr-proposal-show.php?id=198) package. using can encode , unable decode tried read doc , didn't understand anything.here code:
<?php include("/home/gpreeti/php/json.php"); $json = new services_json(); $marks = array( "mohammad" => array ( "physics" => 35, "maths" => 30, "chemistry" => 39 ), "qadir" => array ( "physics" => 30, "maths" => 32, "chemistry" => 29 ), "zara" => array ( "physics" => 31, "maths" => 22, "chemistry" => 39 ) ); $marks=$json->encode($marks); print"$marks\n"; $marks = $json->decode($marks); #var_dump($marks); print"$marks"; ?>
on running , getting this
{"mohammad":{"physics":35,"maths":30,"chemistry":39},"qadir":{"physics":30,"maths":32,"chemistry":29},"zara":{"physics":31,"maths":22,"chemistry":39}} php catchable fatal error: object of class stdclass not converted string in /servers/scratch05/gpreeti/php_pgms/test_json.php on line 26
please help, thanks
when have array/object need display using print_r / var_dump
. print used string
$marks=$json->encode($marks); print"$marks\n"; $marks = $json->decode($marks); #var_dump($marks); print_r($marks); //change line
edit array need following changes:
$json = new services_json(services_json_loose_type); $marks = $json->decode($marks);
Comments
Post a Comment