我有一个邮编API的响应。然而,由于两个单词之间有空格,我无法弄清楚如何获取“地名”的值。不太确定接下来该怎么做。
object(stdClass)#1 (4) {
["post code"]=>
string(5) "42223"
["country"]=>
string(13) "United States"
["country abbreviation"]=>
string(2) "US"
["places"]=>
array(1) {
[0]=>
object(stdClass)#2 (5) {
["place name"]=>
string(13) "Fort Campbell"
["longitude"]=>
string(8) "-87.5585"
["state"]=>
string(8) "Kentucky"
["state abbreviation"]=>
string(2) "KY"
["latitude"]=>
string(7) "36.5995"
}
}
}
$array_output = json_decode($str_api_response, TRUE);
将其转换为数组,然后可以引用列访问:echo $array_output['places'][0]['place name'];
。 - scragar