0

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

2
  • 2
    Well have you tried anything? This is a trivial task in either language. Commented Sep 20, 2014 at 23:46
  • Have you tried iterating over "companies"? Commented Sep 20, 2014 at 23:47

1 Answer 1

2

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;
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.