显示来自MaasApi的数据 - 对象

时间:2015-02-13 19:43:44

标签: php

正如标题所说我试图在这里显示数据是我的代码

$mars_temperature = new MaasApi();
$data=$mars_temperature->getLatest();
var_dump($data);
echo $data['sol'];

错误致命错误:不能在最后一行使用stdClass类型的对象作为数组,这里是var_dump:

object(stdClass)[3]
 public 'terrestrial_date' => string '2015-02-09' (length=10)
 public 'sol' => int 893
 public 'ls' => float 287
 public 'min_temp' => float -72
 public 'min_temp_fahrenheit' => float -97.6
 public 'max_temp' => float 2
 public 'max_temp_fahrenheit' => float 35.6
 public 'pressure' => float 890
 public 'pressure_string' => string 'Higher' (length=6)
 public 'abs_humidity' => null
 public 'wind_speed' => null
 public 'wind_direction' => string '--' (length=2)
 public 'atmo_opacity' => string 'Sunny' (length=5)
 public 'season' => string 'Month 10' (length=8)
 public 'sunrise' => string '2015-02-09T12:23:00Z' (length=20)
 public 'sunset' => string '2015-02-10T00:39:00Z' (length=20)

更新

以下是API的代码:https://github.com/dbough/MaasApi/blob/master/MaasApi.php

1 个答案:

答案 0 :(得分:1)

要访问对象属性,请使用对象运算符:->

echo $data->sol;

要回显您在评论中引用的属性,请使用:

echo $data->max_temp;
echo $data->min_temp;
相关问题