php count function not working

I am developing a plugin that will show users treehouse profile info. I am getting profile data in json formate and echoing out required data. The problem I’m facing is counting the number of badges of the user I’m using this code in one file :

 <h2 class="handel"><span><?php echo $  wptreehouse_profile->{'name'}; ?></span></h2>      <div class="inside">         <p><img src="<?php echo $  wptreehouse_profile->{'gravatar_url'}; ?>" alt="William Jenning" width="100%" class="wptreehouse-gravatar"></p>         <ul class="wptreehouse-badges-points">             <li>Badges: <strong class="points"><?php echo count( $  wptreehouse_profile->{'badges'}); ?></strong></li>             <li >Points: <strong class="points"><?php echo $  wptreehouse_profile->{'points'}->{'total'}; ?></strong></li>         </ul>      </div> 

Thats the output it is showing 129 badges enter image description here

But when I use the same count function in another file its showing 0 That’s the code `

 <p>        <label for="title">Title</label>        <input type="text" name="<?php echo $  this->get_field_name('title') ?>"         class="widefat" value="<?php echo $  title; ?>">      </p>      <p>        Total Badges:        <?php echo count( $  wptreehouse_profile->{'badges'}); ?>      </p>     <p>       <label for="">How many of your most recent badges would you like to        display?</label>       <input type="text" size="4" name="<?php echo $  this-        >get_field_name('num_badges'); ?>" value="<?php echo $  num_badges; ?>">    </p>    <p>      <label for="">Display tooltips?</label>      <input type="checkbox" name="<?php echo $  this-        >get_field_name('display_tooltip'); ?>" value="1" <?php        checked($  display_tooltip,1); ?>>    </p>` 

And that’s the output total badges:0 enter image description here

I’m not able to find what’s the problem because i copy paste the code and still it’s not working.Please guide me where is the problem.