【发布时间】:2014-09-23 15:52:45
【问题描述】:
我有一个邮政编码 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'];