-3
好吧我已经看了几个例子,我似乎无法显示数组或元素。它不断返回为空。我有以下的JSON(从Mapquest服务)json_decode无法显示数组
renderGeocode({
results: [
{
locations: [
{
latLng: {
lng: -90.1978,
lat: 38.627201
},
adminArea4: "Saint Louis City",
adminArea5Type: "City",
adminArea4Type: "County",
adminArea5: "Saint Louis",
street: "",
adminArea1: "US",
adminArea3: "MO",
type: "s",
displayLatLng: {
lng: -90.1978,
lat: 38.627201
},
linkId: 0,
postalCode: "",
sideOfStreet: "N",
dragPoint: false,
adminArea1Type: "Country",
geocodeQuality: "CITY",
geocodeQualityCode: "A5XAX",
mapUrl: "http://www.mapquestapi.com/staticmap/v4/getmap?key=123456789&type=map&size=225,160&pois=purple-1,38.627201,-90.1978,0,0|¢er=38.627201,-90.1978&zoom=12&rand=1390479880",
adminArea3Type: "State"
}
],
providedLocation: {
location: "SAint Louis,mo"
}
}
],
options: {
ignoreLatLngInput: false,
maxResults: -1,
thumbMaps: true
},
info: {
copyright: {
text: "© 2013 MapQuest, Inc.",
imageUrl: "http://api.mqcdn.com/res/mqlogo.gif",
imageAltText: "© 2013 MapQuest, Inc."
},
statuscode: 0,
messages: [
]
}
})
我试图将它添加到一个数组,像这样
$array =json_decode($data, true);
但是不管我怎么尝试打印或检查内容这一切回来作为null我真的只是试图打印出经纬度和adminArea5。 任何帮助将是伟大的。
下面是完整的代码
<?php
$where = filter_input(INPUT_GET, 'where', FILTER_SANITIZE_STRING);
$source = "getLat";
if ($source =="getLat")
{
ob_start();
$getsource = array('location' =>$where,
'type'=>$getWhat,
'callback'=>'ResultSet'
);
$url = "http://www.mapquestapi.com/geocoding/v1/address?key=123456789" . http_build_query($getsource, '', "&");
//print_r($url);
$data_mapquest = file_get_contents($url);
$array = json_decode($data_mapquest, true);
ob_end_flush();
}
?>
这看起来不像JSON ... – elclanrs 2013-04-23 02:20:50
这不是JSON。这是一个Javascript表达式。除了函数调用换行之外,键不加引号。这就是为什么普通的'json_decode'在这里不起作用。 – mario 2013-04-23 02:21:00
好的 - 任何建议 - 我有点新手在这里,但任何指导将是伟大的 – 2013-04-23 02:22:29