Javascript 从JSON对象获取字符串
我有一个名为$graphData的JSON对象,当我使用Javascript 从JSON对象获取字符串,javascript,php,json,Javascript,Php,Json,我有一个名为$graphData的JSON对象,当我使用时,我得到以下信息: object(stdClass)[987] public 'myself' => object(stdClass)[984] public '1' => object(stdClass)[986] public 'id' => string '999999999' (length=9) public 'value' =
时,我得到以下信息:
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)
...
如何访问标记为“value”且值为4.2的字符串
谢谢
//编辑:我需要在php中使用它,或者在php中使用js代码:
$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;
你试过什么吗?在这两种语言中,这都是一项微不足道的任务。你有没有尝试过在“公司”中迭代?是的,我正在“我自己”下寻找一个。谢谢