如何在PHP中从JSON回显特定键=>值对

时间:2018-07-23 19:41:18

标签: php json

我正在访问本地网络中的API。我需要将某些值用于其他用途,但是我不知道如何从此JSON数组中获取特定的key => value对。

要获取JSON,我有:

$url = 'http://192.168.123.123/api/dev';
$result = file_get_contents($url);
$resultData = json_decode($result);
//echo "<pre>";
print_r($resultData);
echo "<br>";

哪个给我:

 stdClass Object ( [data] => stdClass Object ( [1E5410ECC9D90FC3] => stdClass Object ( [type] => BB-TH [state] => normal [alarm] => stdClass Object ( [state] => none [severity] => ) [name] => Watchdog 15 [label] => Watchdog 15 [entity] => stdClass Object ( [0] => stdClass Object ( [name] => Watchdog 15 [alarm] => stdClass Object ( [state] => none [severity] => ) [measurement] => stdClass Object ( [0] => stdClass Object ( [type] => temperature [value] => 62.61 [state] => normal [alarm] => stdClass Object ( [state] => clear [severity] => ) [units] => F [datalogEnabled] => 1 ) [1] => stdClass Object ( [type] => humidity [value] => 47 [state] => normal [alarm] => stdClass Object ( [state] => none [severity] => ) [datalogEnabled] => 1 ) [2] => stdClass Object ( [type] => dewpoint [value] => 42.13 [state] => normal [alarm] => stdClass Object ( [state] => none [severity] => ) [units] => F [datalogEnabled] => 1 ) ) ) ) [layout] => stdClass Object ( [0] => Array ( [0] => entity/0 ) ) [order] => 0 [temperatureOffset] => 0 [snmpInstance] => 1 ) ) [retCode] => 0 [retMsg] => ) 

我需要的是:

temperature [value] => 62.61

但是我不知道获取它的语法。

1 个答案:

答案 0 :(得分:-2)