Php 从JSON数组获取值

Php 从JSON数组获取值,php,json,Php,Json,我正在使用Mapquest试图获取请求地址的纬度和经度值 这是我对他们API的调用: $json = file_get_contents('http://www.mapquestapi.com/geocoding/v1/address?key=******&callback=renderOptions&outFormat=json&inFormat=json&json={location:{street:"Lancaster,PA"},options:{thumb

我正在使用Mapquest试图获取请求地址的纬度和经度值

这是我对他们API的调用:

$json = file_get_contents('http://www.mapquestapi.com/geocoding/v1/address?key=******&callback=renderOptions&outFormat=json&inFormat=json&json={location:{street:"Lancaster,PA"},options:{thumbMaps:false}}');

$output = json_decode($json, true);

$lat = $output['results'][0]['locations'][0]['latLng']['lat'];
$lng = $output['results'][0]['locations'][0]['latLng']['lng'];

echo $lat.",".$lng;
如您所见,我试图将
LAT
LNG
回送到屏幕,但它是空的。当我打印($json)时,我得到以下信息:

渲染({“结果”:[{“位置”:[{“latLng”:{“lng”:-76.30127,“lat”:40.03804},“管理区域4”:“兰开斯特” 县“,”行政区域5类型“:”城市“

所以我知道响应是正常的,
LAT
LNG
是可用的,但是如果我
print\r($output)
我什么也得不到,如果我
var\u dump($output)
我得到NULL,显然我没有得到我的LAT LNG数据


我对JSON和数组不太在行。有人能看出我做错了什么吗?

您需要从URL中删除
&callback=renderOptions
。现在,服务器返回JSONP(使用指定的回调函数)。这不是有效的JSON,因此
JSON\u decode
返回
NULL
(如手册中所述)

非常感谢。我从来没有想到,或者如果我真的想到了,那就太晚了一周!不客气;)我真的知道,因为我花了两周时间与JSONP合作(直到我们决定改用其他东西……)