获取从JSON对象

问题描述:

字符串我有一个名为$ graphData一个JSON对象,当我使用<?php echo var_dump(json_decode($graphData)); ?>我得到如下:获取从JSON对象

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) 
       ... 

如何访问标有“价值”的字符串,并与值4.2?

感谢

//编辑:我需要在PHP或JS代码

+2

那么你尝试什么?这是两种语言中的一项微不足道的任务。 – Qix 2014-09-20 23:46:25

+0

你有没有尝试迭代“公司”? – 2014-09-20 23:47:13

使用它在PHP:

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

在JavaScript:

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

是的,我正在寻找“我自己”下的那个。谢谢! – nullbuilt 2014-09-21 00:03:29