我正在尝试编写 PHP 代码来与 Mapquest 的 Open API / Open Street Map 服务的 JSON 输出进行交互。我在下面列出了它。我一直在我的 Drupal 6 实现中使用此代码。此代码不返回任何输出。当我使用它时,json_last_error()
输出 0。
function json_test_page() {
$url = 'http://open.mapquestapi.com/directions/v1/route?outFormat=json&from=40.037661,-76.305977&to=39.962532,-76.728099';
$json = file_get_contents($url);
$obj = json_decode(var_export($json));
$foo .= $obj->{'fuelUsed'};
$output .= foo;
return $output;
}
您可以通过URL查看原始 JSON 输出。在这个函数中,我期望得到1.257899
我的输出。我有两个问题:
(1) 我可以调用什么来从数组中取出物品。例如,如何"distance":26.923
从数组中获取 JSON 中表示的值?
(2) 我是否有可能遇到我在PHP 手册中读到的递归限制问题?