繁体   English   中英

从JSON对象获取字符串

[英]Get string from JSON object

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

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代码中使用它

在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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM