如何在 PHP 中使用 Httpfull 从 REST JSON 响应中获取特定属性

How to get specific properties from a REST JSON response using Httpfull in PHP

我想显示姓名、城市等,我不想只显示部分数据。

<?php    
 $url='my url';
$res = \Httpful\Request::get($url)->expectsJson()->send();
$data = json_decode($res,true);
print_r($data);  ?>

输出为:

Array ( [message] => OK [property] => Array ( [id] => 193547 [broker_id] => 4772 [second_broker_id] => 7530 [third_broker_id] => 4695 [address] => 534 Canyon Drive [city] => Eyota [state] => MN [zip] => 55934 [county] => Olmsted [market] => [submarket] => [cross_streets] => [location_description] => The Subject Property is positioned along Hwy 42, the road from Interstate 90 heading into Eyota. Adjacent to the property is a 34-unit assisted living/memory care center, as well as a small residential development. Less than 1 mile away is the city’s West Side Park, which has 2 baseball fields, a skate park, sand volleyball courts and it even hosts a farmers market during warmer summer months. Eyota has a population of 2,025 and is just 13 miles east of Rochester, which has a population of 100,000. [latitude] => 43.995568 [longitude] => -92.24475 [name] => Dollar General #17079 [property_type_id] => 2 [property_subtype_id] => 203 [additional_property_subtype_ids] => Array ( )

如果你想要特定的数据,直接用密钥访问它。

按照你的例子:

$data = json_decode($res,true);
$name =  $data['properties'][0]['name'];
$city =  $data['properties'][0]['city'];