[wp-trac] [WordPress Trac] #11963: json_decode() only supports only "stdClass Object" but no "array"

WordPress Trac wp-trac at lists.automattic.com
Thu Jan 21 15:36:51 UTC 2010


#11963: json_decode() only supports only "stdClass Object" but no "array"
--------------------------+-------------------------------------------------
 Reporter:  carbolineum   |       Owner:                    
     Type:  enhancement   |      Status:  new               
 Priority:  normal        |   Milestone:  Unassigned        
Component:  Optimization  |     Version:  2.9.1             
 Severity:  normal        |    Keywords:  json_decode, array
--------------------------+-------------------------------------------------

Comment(by carbolineum):

 Hi nacin,

 you are right, i didn't consider the one-time initialisation. Perhaps a
 conversion like this could be a solution:

 {{{
 function ObjToArr($data) {
     if (is_object($data)) $data = get_object_vars($data);
     return is_array($data) ? array_map(__FUNCTION__, $data) : $data;
 }

 if ( !function_exists('json_decode') ) {
         function json_decode( $string, $bool ) {
                 global $wp_json;

                 if ( !is_a($wp_json, 'Services_JSON') ) {
                         require_once( 'class-json.php' );
                         $wp_json = new Services_JSON();
                 }

                 if ($bool === TRUE) {
                         return ObjToArr($wp_json->decode( $string ));
                 }
                 else {
                         return $wp_json->decode( $string );
                 }
         }
 }
 }}}

 Greetings Michael

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/11963#comment:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list