Stack Exchange
Get string from JSON object
I have a JSON object called $graphData, and when I use <?php echo var_dump(json_decode($graphData)); ?> I get the following:
object(stdClass)[987]
  public 'myself' => 
    object(stdClass)[984]
      public '1' => 
        object(stdClass)[986]
          public 'id' => string '999999999' (length=9)
          public 'value' => string '4.2' (length=3)
          public 'name' => string 'Myself' (length=6)
          public 'owner' => string '' (length=0)
          public 'type' => int 1
          public 'children' => 
            array (size=0)
              ...
  public 'my_teams' => 
    array (size=0)
      empty
  public 'my_units' => 
    array (size=0)
      empty
  public 'companies' => 
    array (size=1)
      0 => 
        object(stdClass)[982]
          public 'id' => string '66' (length=2)
          public 'name' => string 'Company' (length=8)
          public 'owner' => string 'Name Name' (length=13)
          public 'value' => string '4.2' (length=3)
          public 'type' => string '4' (length=1)
          public 'children' => 
            array (size=0)
              ...

How can I access the string labeled 'value', and with value 4.2?
Thanks
//Edit: I need to use it in php or js code

Well have you tried anything? This is a trivial task in either language.

Have you tried iterating over "companies"?

In PHP:
$data = json_decode($graphData);
$value = $data->companies[0]->value;
//Or for the one stored under "myself"
$value = $data->myself->{'1'}->value;

In JavaScript:
var value = data.companies[0].value;
//Or for the one stored under "myself"
value = data.myself[1].value;


Yes, I was looking for the one under "myself". Thanks!
