tags:

views:

82

answers:

4

When I try to find out the total count of delicious bookmarks, Delicious returns a json file which when decoded is:

Array ( 
    [0] => stdClass Object ( 
        [hash] => e60558db2d649c8a1933d50f9e5b199a 
        [title] => ISRAEL: Thousands march in Jerusalem rally, Israel still kicking 
                       new families out of land they've owned for 60+ years 
        [url] => http://english.aljazeera.net/news/middleeast/2010/03/2010362141312196.html
        [total_posts] => 2 
        [top_tags] => Array () 
     )
)

The array is a stdClass Object. How can I extract [total_count] using PHP.

P.S Since I could not figure out how to extract it, I am using strpos to find 'total_count' and then I am cutting the string from that position and then extracting integers out of it. :) BUt it is way too long.

Solved

A: 

Have you tried

echo $stdClass->total_posts;
Pentium10
A: 

Do you mean [total_posts]? If so, you should use $delArray[0]->total_posts.

See http://us.php.net/manual/en/language.types.object.php for samples on accessing object properties.

Andy E
+1  A: 

If you pass a second argument, true, in your json_decode, it will return a regular array as opposed to an object. You might find this easier to work with.

$array = json_decode($json, true);

abloodywar
Forgot to add 'true'... :) thanks
Jagira
+4  A: 

If you pass a second argument, true, in your json_decode, it will return a regular array as opposed to an object. You might find this easier to work with.

$array = json_decode($json, true);
We love stackoverflow